Add version and git commit ID as HTML tag during Docker build process #116
Workflow file for this run
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: Docker Image CI | |
on: | |
push: | |
branches: | |
- "master" | |
tags: | |
- "v*.*.*" | |
pull_request: | |
branches: | |
- "master" | |
jobs: | |
docker: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Get the version tag | |
id: get_version | |
run: | | |
TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "no-tag") | |
echo "::set-output name=version::$TAG" | |
- name: Get the commit ID | |
id: get_commit | |
run: echo "::set-output name=commit::$(git rev-parse HEAD)" | |
- name: Inject version and commit ID into index.ejs | |
run: | | |
VERSION=$(echo "${{ steps.get_version.outputs.version }}") | |
COMMIT=$(echo "${{ steps.get_commit.outputs.commit }}") | |
sed -i "\$a<!-- Version: $VERSION, Commit ID: $COMMIT -->" views/index.ejs | |
- name: Docker meta | |
id: meta | |
uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7 | |
with: | |
# list of Docker images to use as base name for tags | |
images: | | |
wemove/read2burn | |
tags: | | |
type=raw,value=latest | |
type=semver,pattern={{version}} | |
type=semver,pattern={{major}} | |
type=semver,pattern={{major}}.{{minor}} | |
- name: Set up QEMU | |
uses: docker/setup-qemu-action@v3 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
- name: Login to Docker Hub | |
uses: docker/login-action@f4ef78c080cd8ba55a85445d5b36e214a81df20a | |
with: | |
username: ${{ secrets.DOCKERHUB_USERNAME }} | |
password: ${{ secrets.DOCKERHUB_TOKEN }} | |
- name: Build and push | |
id: push | |
uses: docker/build-push-action@3b5e8027fcad23fda98b2e3ac259d8d67585f671 | |
with: | |
context: . | |
push: ${{ github.event_name != 'pull_request' }} | |
file: docker/Dockerfile | |
tags: ${{ steps.meta.outputs.tags }} | |
labels: ${{ steps.meta.outputs.labels }} |