-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docker container publishing workflow
- Loading branch information
Showing
1 changed file
with
43 additions
and
0 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -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 |