diff --git a/.github/workflows/container_publishing.yml b/.github/workflows/container_publishing.yml new file mode 100644 index 0000000..4891e30 --- /dev/null +++ b/.github/workflows/container_publishing.yml @@ -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 \ No newline at end of file