diff --git a/.github/workflows/nightly.yml b/.github/workflows/nightly.yml index df6b81e2d..e7e31a282 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' @@ -32,9 +34,26 @@ jobs: # run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login docker.pkg.github.com -u ${{ github.actor }} --password-stdin # Build images - - name: Build docker image - run: ./build-n-push.sh --tag dev + - 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 + 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 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} }