Merge remote-tracking branch 'origin/main' #8
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
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 Initial Version | |
id: set_version | |
run: | | |
VERSION="1.0.0" | |
IMAGE_NAME="${{ secrets.DOCKERHUB_USERNAME }}/karos-repo" | |
# 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 | |
# Export the new version | |
echo "VERSION=$VERSION" >> $GITHUB_ENV | |
- name: Build the Docker image | |
run: | | |
docker build . \ | |
--file Dockerfile \ | |
--tag ${{ secrets.DOCKERHUB_USERNAME }}/karos-repo:${{ env.VERSION }} | |
- name: Docker Push | |
run: docker push ${{ secrets.DOCKERHUB_USERNAME }}/karos-repo:${{ env.VERSION }} |