From 0621d4a11e1409bb68aa327f23510f64d33b0690 Mon Sep 17 00:00:00 2001 From: Michael Mulich Date: Tue, 12 Jul 2022 12:20:21 -0700 Subject: [PATCH 1/5] Allow building of specified branches/tags --- prod/Dockerfile | 3 ++- prod/build-n-push.sh | 17 ++++++++++++----- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/prod/Dockerfile b/prod/Dockerfile index 242aafd27..4e5422a86 100644 --- a/prod/Dockerfile +++ b/prod/Dockerfile @@ -1,7 +1,8 @@ FROM node:lts as dist-build +ARG git_ref=develop RUN set -x \ && cd /tmp \ - && git clone https://github.com/WildMeOrg/codex-frontend.git + && git clone --branch ${git_ref} https://github.com/WildMeOrg/codex-frontend.git # Install dependencies & build distribution RUN set -ex \ && cd /tmp/codex-frontend \ diff --git a/prod/build-n-push.sh b/prod/build-n-push.sh index 88cd1e041..1f2dae63d 100755 --- a/prod/build-n-push.sh +++ b/prod/build-n-push.sh @@ -1,6 +1,7 @@ #!/usr/bin/env bash -tag=${TAG-latest} +tag=latest +git_ref=develop repo=${REPO-wildme} @@ -9,12 +10,13 @@ function print_help(){ Usage: ${0} ARGS Optional Arguments: - --tag image tag name (default: latest) + --tag image tag name (default: $tag) + --git-ref git reference name (default: $git_ref) --repo repo the image resides (default: wildme) Example: - ${0} --tag dev --repo mmulich - # results in building and pushing the mmulich/codex-frontend:dev image + ${0} --tag main --git-ref main --repo mmulich + # results in building and pushing the mmulich/codex-frontend:main image EOF } @@ -28,6 +30,11 @@ do shift shift ;; + --git-ref) + git_ref="$2" + shift + shift + ;; --repo) repo="$2" shift @@ -53,7 +60,7 @@ done function main() { - docker build --no-cache -t ${repo}/codex-frontend:${tag} . + docker build --no-cache --build-arg git_ref=$git_ref -t ${repo}/codex-frontend:${tag} . docker push ${repo}/codex-frontend:${tag} } From c4fcba8405bd593b99a16092e6a637ac6cf9434b Mon Sep 17 00:00:00 2001 From: Michael Mulich Date: Tue, 12 Jul 2022 13:02:36 -0700 Subject: [PATCH 2/5] Build and push any branch --- .github/workflows/nightly.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/nightly.yml b/.github/workflows/nightly.yml index df6b81e2d..6f4fb4ed1 100644 --- a/.github/workflows/nightly.yml +++ b/.github/workflows/nightly.yml @@ -33,7 +33,9 @@ jobs: # Build images - name: Build docker image - run: ./build-n-push.sh --tag dev + run: | + TAG=$(echo ${GITHUB_REF_NAME} | sed 's/^v\([0-9.].\)/\1/') + ./build-n-push.sh --tag ${TAG} --git-ref ${GITHUB_REF_NAME} working-directory: ./prod # Notify status in Slack From d055fd8fa70bdaba0f19f5e9baaa119aa1a5eb01 Mon Sep 17 00:00:00 2001 From: Michael Mulich Date: Tue, 12 Jul 2022 13:04:19 -0700 Subject: [PATCH 3/5] Build and push image for main, develop and tags --- .github/workflows/nightly.yml | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/.github/workflows/nightly.yml b/.github/workflows/nightly.yml index 6f4fb4ed1..43dfd6eb4 100644 --- a/.github/workflows/nightly.yml +++ b/.github/workflows/nightly.yml @@ -3,9 +3,11 @@ on: schedule: - cron: '0 16 * * *' # Every day at 16:00 UTC (~09:00 PT) push: - paths: - - '.github/workflows/nightly.yml' - - 'prod/**' + branches: + - main + - develop + tags: + - v* pull_request: paths: - '.github/workflows/nightly.yml' From e64c4baab6131064fd8100805360a487280958f1 Mon Sep 17 00:00:00 2001 From: Michael Mulich Date: Tue, 12 Jul 2022 13:10:50 -0700 Subject: [PATCH 4/5] Tag and push latest image on versioned tag build --- .github/workflows/nightly.yml | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/.github/workflows/nightly.yml b/.github/workflows/nightly.yml index 43dfd6eb4..285460407 100644 --- a/.github/workflows/nightly.yml +++ b/.github/workflows/nightly.yml @@ -40,6 +40,14 @@ jobs: ./build-n-push.sh --tag ${TAG} --git-ref ${GITHUB_REF_NAME} working-directory: ./prod + # Push tagged image with latest tagging + - name: Push latest tag + if: ${{ github.event_name == 'push' && startsWith(github.event.ref, 'refs/tags/v') }} + run: | + TAG=$(echo ${GITHUB_REF_NAME} | sed 's/^v\([0-9.].\)/\1/') + docker tag wildme/codex-frontend:${TAG} wildme/codex-frontend:latest + docker push wildme/codex-frontend:latest + # Notify status in Slack - name: Slack Notification if: failure() && github.event_name == 'schedule' From 89f9ee44b11e118d1882dc1d44ac64f8eab516a1 Mon Sep 17 00:00:00 2001 From: Michael Mulich Date: Tue, 12 Jul 2022 13:22:20 -0700 Subject: [PATCH 5/5] Build and tag pull requests image --- .github/workflows/nightly.yml | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/.github/workflows/nightly.yml b/.github/workflows/nightly.yml index 285460407..e7e31a282 100644 --- a/.github/workflows/nightly.yml +++ b/.github/workflows/nightly.yml @@ -34,11 +34,18 @@ jobs: # run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login docker.pkg.github.com -u ${{ github.actor }} --password-stdin # Build images - - name: Build docker image + - name: Build docker image (push) + if: ${{ github.event_name == 'push' }} run: | TAG=$(echo ${GITHUB_REF_NAME} | sed 's/^v\([0-9.].\)/\1/') ./build-n-push.sh --tag ${TAG} --git-ref ${GITHUB_REF_NAME} working-directory: ./prod + - name: Build docker image (pull_request) + if: ${{ github.event_name == 'pull_request' }} + run: | + TAG=$(echo ${GITHUB_REF_NAME} | sed 's/([0-9].\)\/merge/pr-\1/') + ./build-n-push.sh --tag ${TAG} --git-ref ${GITHUB_REF_NAME} + working-directory: ./prod # Push tagged image with latest tagging - name: Push latest tag