Update docker-image.yml #3
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 Push Docker Image with Version from version.txt | |
on: | |
push: | |
branches: | |
- docker | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
# Read version from version.txt and add 'v' prefix | |
- name: Get version from version.txt | |
id: get_version | |
run: | | |
VERSION=$(cat version.txt) | |
VERSION="v$VERSION" # Add 'v' prefix to the version | |
echo "VERSION=$VERSION" >> $GITHUB_ENV | |
# Log in to Docker Hub (or GHCR) | |
- name: Log in to Docker Hub | |
uses: docker/login-action@v2 | |
with: | |
username: ${{ secrets.DOCKER_USERNAME }} | |
password: ${{ secrets.DOCKER_PASSWORD }} | |
# Build and push Docker image using version with 'v' prefix | |
- name: Build and push Docker image | |
run: | | |
docker build -t your-dockerhub-username/your-image-name:${{ env.VERSION }} . | |
docker push your-dockerhub-username/your-image-name:${{ env.VERSION }} |