Skip to content

Commit

Permalink
Small fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
fabioassuncao committed Feb 18, 2024
1 parent 152b966 commit dfd6739
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 29 deletions.
File renamed without changes.
102 changes: 74 additions & 28 deletions .github/workflows/docker-publish.yaml
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"
4 changes: 3 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ version: '2'
services:

app:
build: .
build:
context: .
dockerfile: .docker/Dockerfile
# image: ghcr.io/codions/revive-adserver/revive-adserver:latest
restart: unless-stopped
depends_on:
Expand Down

0 comments on commit dfd6739

Please sign in to comment.