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, Tag, and Push Docker Image to Docker Hub & GHCR | |
on: | |
push: | |
branches: | |
- master | |
jobs: | |
build-and-push: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
- name: Get current tag version | |
id: version | |
run: | | |
latest_tag=$(git describe --tags --abbrev=0) | |
if [ -z "$latest_tag" ]; then | |
echo "::set-output name=version::v1.0" | |
else | |
version_number=$(echo $latest_tag | sed 's/v//') | |
IFS='.' read -ra version_parts <<< "$version_number" | |
next_version="${version_parts[0]}.${version_parts[1]}.$((${version_parts[2]} + 1))" | |
echo "::set-output name=version::v$next_version" | |
fi | |
- name: Log in to Docker Hub | |
uses: docker/login-action@v2 | |
with: | |
username: gautampatil1 | |
password: ${{ secrets.DOCKER_PASSWORD }} | |
- name: Build Docker image | |
run: docker build -t gautampatil1/rezume:${{ steps.version.outputs.version }} . | |
- name: Push Docker image to Docker Hub | |
run: docker push gautampatil1/rezume:${{ steps.version.outputs.version }} | |
- name: Push Docker image to ghcr.io | |
run: | | |
docker login --username gautampatil1 --password ${{ secrets.GH_PAT }} ghcr.io | |
docker tag gautampatil1/rezume:${{ steps.version.outputs.version }} ghcr.io/gautampatil1/rezume:${{ steps.version.outputs.version }} | |
docker push ghcr.io/gautampatil1/rezume:${{ steps.version.outputs.version }} | |