Skip to content

Commit

Permalink
Updated github/workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
fabioassuncao committed Feb 18, 2024
1 parent 681413c commit 1764c79
Showing 1 changed file with 28 additions and 74 deletions.
102 changes: 28 additions & 74 deletions .github/workflows/docker-publish.yaml
Original file line number Diff line number Diff line change
@@ -1,102 +1,56 @@
name: Flow Main
name: Docker Build/Publish CI

on:
push:
# Publish `main` as Docker `latest` image.
branches:
- main

# Publish `v1.2.3` tags as releases.
tags:
- v*

# Create a button to trigger the workflow manually.
workflow_dispatch:
# Run tests for any PRs.
pull_request:

env:
# TODO: Change variable to your image's name.
IMAGE_NAME: revive-adserver

jobs:
bump-version:
# Push image to GitHub Packages.
# See also https://docs.docker.com/docker-hub/builds/
push:
runs-on: ubuntu-latest
outputs:
VERSION: ${{ steps.version.outputs.VERSION }}
steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Set version
id: version
run: |
# Strip git ref prefix from version
VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,')
if: github.event_name == 'push'

# 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\"}" > $GITHUB_WORKSPACE/www/version.json
- name: Upload version.json
uses: actions/upload-artifact@v2
with:
name: version-json
path: www

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: www
- uses: actions/checkout@v2

- name: Checkout repository
uses: actions/checkout@v3
- name: Build image
run: docker build . --file Dockerfile --tag $IMAGE_NAME

- name: Build Docker image
run: docker build . --file .docker/Dockerfile --tag $IMAGE_NAME

- name: Login into registry
- name: Log 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 }}
- name: Push image
run: |
IMAGE_ID=docker.pkg.github.com/${{ github.repository }}/$IMAGE_NAME
# Use Docker `latest` tag convention
if [ "$VERSION" == "main" ] || [ "$VERSION" == "merge" ] || [ "$VERSION" == "edge" ]; then
VERSION="latest"
fi
# 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
# Strip git ref prefix from version
VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,')
echo "IMAGE_TAG=$VERSION" >> $GITHUB_OUTPUT
# Strip "v" prefix from tag name
[[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION=$(echo $VERSION | sed -e 's/^v//')
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"
# Use Docker `latest` tag convention
[ "$VERSION" == "main" ] && VERSION=latest
echo IMAGE_ID=$IMAGE_ID
echo VERSION=$VERSION
docker tag $IMAGE_NAME $IMAGE_ID:$VERSION
docker push $IMAGE_ID:$VERSION

0 comments on commit 1764c79

Please sign in to comment.