Skip to content

Commit

Permalink
docker container publishing workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
cedricdcc committed Apr 25, 2024
1 parent a0cc2a4 commit db6dbd4
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions .github/workflows/container_publishing.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: Docker Image Build & Push to ghrc.io

on:
push:
branches: [ "main" ]
tags: [ "v*.*.*" ]
pull_request:
branches: [ "main" ]
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout the codebase
uses: actions/checkout@v3

- name: Login to GitHub Container Registry
uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract tag name
id: get_tag
run: echo ::set-output name=TAG_NAME::${GITHUB_REF#refs/tags/}
- name: Use tag name
run: echo ${{ steps.get_tag.outputs.TAG_NAME }}
- name: Build the Docker image
run: |
export REG_NS=ghcr.io/vlizbe/
TAG_NAME=${GITHUB_REF#refs/tags/}
# build tag is the same as tag name for releases if this matches the semver format else it is latest
# The string you want to check
# The regular expression
regex="^(0|[1-9][0-9]*)\\.(0|[1-9][0-9]*)\\.(0|[1-9][0-9]*)(-((0|[1-9][0-9]*|[0-9]*[a-zA-Z-][0-9a-zA-Z-]*)(\\.(0|[1-9][0-9]*|[0-9]*[a-zA-Z-][0-9a-zA-Z-]*))*))?(\\+([0-9a-zA-Z-]+(\\.[0-9a-zA-Z-]+)*))?$"
if [[ $TAG_NAME =~ $regex ]]; then
export BUILD_TAG=$TAG_NAME
else
export BUILD_TAG="latest"
fi
echo $BUILD_TAG
docker build -t $REG_NS$GITHUB_REPOSITORY_NAME:$BUILD_TAG .
docker push $REG_NS$GITHUB_REPOSITORY_NAME:$BUILD_TAG

0 comments on commit db6dbd4

Please sign in to comment.