From 6799028dffb2a42ef42f6ddece7bf6fd2b569992 Mon Sep 17 00:00:00 2001 From: timmypidashev Date: Sun, 12 Nov 2023 00:00:43 -0800 Subject: [PATCH] Add build-time args --- compose.dev.yml | 5 +++-- dns/Dockerfile.dev | 8 ++++++++ version.toml | 8 ++++---- web | 30 ++++++++++++++++++++++++------ 4 files changed, 39 insertions(+), 12 deletions(-) diff --git a/compose.dev.yml b/compose.dev.yml index 5af9e60..adffc3e 100644 --- a/compose.dev.yml +++ b/compose.dev.yml @@ -8,5 +8,6 @@ services: context: ./dns dockerfile: Dockerfile.dev args: - - BUILD_DATE=${BUILD_DATE} - - GIT_COMMIT=${GIT_COMMIT} + - DNS_VERSION + - BUILD_DATE + - GIT_COMMIT diff --git a/dns/Dockerfile.dev b/dns/Dockerfile.dev index 0a5b847..8b90a58 100644 --- a/dns/Dockerfile.dev +++ b/dns/Dockerfile.dev @@ -1,3 +1,11 @@ +# Imported args +ARG BUILD_DATE +ARG GIT_COMMIT +ARG DNS_VERSION + +# Print the values of the build arguments +RUN echo "DNS_VERSION=$DNS_VERSION" + # CoreDNS base image ARG ALPINE_VERSION=3.18 ARG GO_VERSION=1.21.3 diff --git a/version.toml b/version.toml index 664e8d0..4649821 100644 --- a/version.toml +++ b/version.toml @@ -1,9 +1,9 @@ # The following version number is incremented whenever -#a local package or service in this repository recieves a version bump! +# a container in this repository recieves a version bump! -[global] +[project] version = "1.0.1" [containers] - -[packages] +dns = "0.0.0" +proxy = "0.0.0" diff --git a/web b/web index 295425c..a9222e3 100755 --- a/web +++ b/web @@ -4,10 +4,23 @@ action="$1" environment="$2" -# Set the build arguments as environment variables -export BUILD_DATE=$(date -u +'%Y-%m-%dT%H:%M:%SZ') -export GIT_COMMIT=$(git rev-parse --short HEAD) +# Pulls project version from version.toml +project_version() { + local version=$(awk -F'[" ]+' '/^\[project\]/{getline; print $3}' "version.toml") + echo "v$version" +} +# Pulls container version from version.toml +container_version() { + local container="$1" + local version=$(awk -F'[" ]+' -v container="$container" '/^\[containers\]/{block=$1} block == "[containers]" && $1 == container {getline; print $3}' "version.toml") + echo "v$version" +} + +# Set the build arguments as environment variables +BUILD_DATE=$(date -u +'%Y-%m-%dT%H:%M:%SZ') +GIT_COMMIT=$(git rev-parse --short HEAD) +PROJECT_VERSION=$(project_version) case $action in help) @@ -21,8 +34,8 @@ case $action in echo "" echo "Actions:" echo " * build" - echo " - builds either the entire stack without cache or select container" - echo " - example: '{action} {environment}' or '{action} {container} {environment}'" + echo " - builds the entire stack without cache" + echo " - example: '{action} {environment}' or '{action} {environment}" echo "" echo " * run" echo " - runs the entire stack with caching enabled" @@ -43,7 +56,12 @@ case $action in build) if [ "$environment" == "dev" ]; then - echo "build dev" + docker compose --file compose.dev.yml build \ + --build-arg BUILD_DATE=$BUILD_DATE \ + --build-arg GIT_COMMIT=$GIT_COMMIT \ + --build-arg PROJECT_VERSION="$PROJECT_VERSION" \ + --build-arg DNS_VERSION=$(container_version "dns") \ + --build-arg PROXY_VERSION=$(container_version "proxy") \ elif [ "$environment" == "prod" ]; then