Skip to content

Merge remote-tracking branch 'origin/main' #11

Merge remote-tracking branch 'origin/main'

Merge remote-tracking branch 'origin/main' #11

Workflow file for this run

#ci
name: Build and Publish Docker Image to DockerHub
on:
push:
branches: ["main"]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: DockerHub Login
uses: docker/[email protected]
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}
- name: Set Version and Build Number
id: set_version
run: |
VERSION="1.0.0"
IMAGE_NAME="${{ secrets.DOCKERHUB_USERNAME }}/karos-repo"
BUILD_NUMBER=${{ github.run_number }}
# Check if the version already exists on Docker Hub
if docker pull $IMAGE_NAME:$VERSION 2>/dev/null; then
# Extract the current major and minor version
MAJOR=$(echo $VERSION | cut -d '.' -f 1)
MINOR=$(echo $VERSION | cut -d '.' -f 2)
PATCH=$(echo $VERSION | cut -d '.' -f 3)
# Increment the patch version
PATCH=$((PATCH + 1))
VERSION="$MAJOR.$MINOR.$PATCH"
fi
# Combine version with build number
TAG="$VERSION-build.$BUILD_NUMBER"
# Export variables
echo "VERSION=$VERSION" >> $GITHUB_ENV
echo "BUILD_NUMBER=$BUILD_NUMBER" >> $GITHUB_ENV
echo "TAG=$TAG" >> $GITHUB_ENV
- name: Build the Docker image
run: |
docker build . \
--file Dockerfile \
--tag ${{ secrets.DOCKERHUB_USERNAME }}/karos-repo:${{ env.TAG }}
- name: Docker Push
run: docker push ${{ secrets.DOCKERHUB_USERNAME }}/karos-repo:${{ env.TAG }}