Skip to content

Commit

Permalink
Added GitHub Workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
fabioassuncao committed Jan 10, 2024
1 parent e985f76 commit 7143e01
Showing 1 changed file with 101 additions and 0 deletions.
101 changes: 101 additions & 0 deletions .github/workflows/ci-main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
name: Flow Main

on:
push:
branches:
- main
tags:
- v*

# Create a button to trigger the workflow manually.
workflow_dispatch:

env:
IMAGE_NAME: app

jobs:
bump-version:
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,')
# 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\"}" > storage/version.json
- name: Upload version.json
uses: actions/upload-artifact@v2
with:
name: version-json
path: storage

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: storage

- 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
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
echo "IMAGE_TAG=$VERSION" >> $GITHUB_OUTPUT
deploy:
runs-on: ubuntu-latest
needs: [docker-ci]
steps:
- name: Deploy on K8s
id: deploy
run: |
COMMIT_NUMBER=$(git rev-parse --short ${{ github.sha }})
echo "Work in progress."
echo "For now, settle for the last commit's ID: $COMMIT_NUMBER"

0 comments on commit 7143e01

Please sign in to comment.