Skip to content
This repository has been archived by the owner on Nov 13, 2024. It is now read-only.

Automate the image build of main, tag and develop git references #429

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 24 additions & 5 deletions .github/workflows/nightly.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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
Expand Down
3 changes: 2 additions & 1 deletion prod/Dockerfile
Original file line number Diff line number Diff line change
@@ -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 \
Expand Down
17 changes: 12 additions & 5 deletions prod/build-n-push.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/usr/bin/env bash

tag=${TAG-latest}
tag=latest
git_ref=develop
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not main?

repo=${REPO-wildme}


Expand All @@ -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
}
Expand All @@ -28,6 +30,11 @@ do
shift
shift
;;
--git-ref)
git_ref="$2"
shift
shift
;;
--repo)
repo="$2"
shift
Expand All @@ -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}
}

Expand Down