-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
152b966
commit dfd6739
Showing
3 changed files
with
77 additions
and
29 deletions.
There are no files selected for viewing
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,56 +1,102 @@ | ||
name: Docker Build/Publish CI | ||
name: Flow Main | ||
|
||
on: | ||
push: | ||
# Publish `main` as Docker `latest` image. | ||
branches: | ||
- main | ||
|
||
# Publish `v1.2.3` tags as releases. | ||
tags: | ||
- v* | ||
|
||
# Run tests for any PRs. | ||
pull_request: | ||
# Create a button to trigger the workflow manually. | ||
workflow_dispatch: | ||
|
||
env: | ||
# TODO: Change variable to your image's name. | ||
IMAGE_NAME: revive-adserver | ||
|
||
jobs: | ||
# Push image to GitHub Packages. | ||
# See also https://docs.docker.com/docker-hub/builds/ | ||
push: | ||
bump-version: | ||
runs-on: ubuntu-latest | ||
if: github.event_name == 'push' | ||
|
||
outputs: | ||
VERSION: ${{ steps.version.outputs.VERSION }} | ||
steps: | ||
- uses: actions/checkout@v2 | ||
|
||
- name: Build image | ||
run: docker build . --file Dockerfile --tag $IMAGE_NAME | ||
- name: Checkout repository | ||
uses: actions/checkout@v3 | ||
|
||
- name: Log into registry | ||
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login docker.pkg.github.com -u ${{ github.actor }} --password-stdin | ||
|
||
- name: Push image | ||
- name: Set version | ||
id: version | ||
run: | | ||
IMAGE_ID=docker.pkg.github.com/${{ github.repository }}/$IMAGE_NAME | ||
# Change all uppercase to lowercase | ||
IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]') | ||
# Strip git ref prefix from version | ||
VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,') | ||
# Strip "v" prefix from tag name | ||
[[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION=$(echo $VERSION | sed -e 's/^v//') | ||
echo "VERSION=$VERSION" >> "$GITHUB_OUTPUT" | ||
# Use Version `edge` tag convention | ||
if [ "$VERSION" == "main" ] || [ "$VERSION" == "merge" ]; then | ||
VERSION=edge | ||
fi | ||
# Update version in project | ||
BUILD_TIMESTAMP=$(TZ=UTC date '+%Y-%m-%d %H:%M:%S %Z') | ||
echo "{\"version\": \"$VERSION\", \"build\": \"$BUILD_TIMESTAMP\"}" > version/version.json | ||
- name: Upload version.json | ||
uses: actions/upload-artifact@v2 | ||
with: | ||
name: version-json | ||
path: version | ||
|
||
docker-ci: | ||
runs-on: ubuntu-latest | ||
needs: [bump-version] | ||
outputs: | ||
IMAGE_TAG: ${{ steps.docker_push.outputs.IMAGE_TAG }} | ||
steps: | ||
- name: Download artifact version.json | ||
uses: actions/download-artifact@v2 | ||
with: | ||
name: version-json | ||
path: version | ||
|
||
- name: Checkout repository | ||
uses: actions/checkout@v3 | ||
|
||
- name: Build Docker image | ||
run: docker build . --file .docker/Dockerfile --tag $IMAGE_NAME | ||
|
||
- name: Login into registry | ||
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login docker.pkg.github.com -u ${{ github.actor }} --password-stdin | ||
|
||
- name: Push Docker image | ||
id: docker_push | ||
env: | ||
VERSION: ${{ needs.bump-version.outputs.VERSION }} | ||
run: | | ||
IMAGE_ID=docker.pkg.github.com/${{ github.repository }}/$IMAGE_NAME | ||
# Use Docker `latest` tag convention | ||
[ "$VERSION" == "main" ] && VERSION=latest | ||
if [ "$VERSION" == "main" ] || [ "$VERSION" == "merge" ] || [ "$VERSION" == "edge" ]; then | ||
VERSION="latest" | ||
fi | ||
echo IMAGE_ID=$IMAGE_ID | ||
echo VERSION=$VERSION | ||
# Change all uppercase to lowercase | ||
IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]') | ||
docker tag $IMAGE_NAME $IMAGE_ID:$VERSION | ||
docker push $IMAGE_ID:$VERSION | ||
echo "IMAGE_TAG=$VERSION" >> $GITHUB_OUTPUT | ||
deploy: | ||
runs-on: ubuntu-latest | ||
needs: [bump-version, docker-ci] | ||
steps: | ||
- name: Deploy on K8s | ||
id: deploy | ||
env: | ||
VERSION: ${{ needs.bump-version.outputs.VERSION }} | ||
run: | | ||
echo "Work in progress 🚀" | ||
echo "For now, settle for the version ID: $VERSION" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters