-
Notifications
You must be signed in to change notification settings - Fork 0
50 lines (44 loc) · 1.62 KB
/
build-docker-image.yml
File metadata and controls
50 lines (44 loc) · 1.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
name: Build and Push Docker Image
on:
push:
tags:
- '*.*.*'
workflow_dispatch:
inputs:
version:
description: 'The version tag to build (e.g., 1.2.3)'
required: true
jobs:
build-and-push:
runs-on: ubuntu-latest
name: build
permissions:
contents: read
packages: write
steps:
- name: Checkout repository
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
with:
# On workflow_dispatch, checkout the tag passed in. On a tag push, checkout the tag from the event.
ref: ${{ github.event.inputs.version || github.ref }}
fetch-depth: 0
- name: Log in to GitHub Container Registry
uses: docker/login-action@b45d80f862d83dbcd57f89517bcf500b2ab88fb2 # v4
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Set version
id: version
run: echo "VERSION=${{ github.event.inputs.version || github.ref_name }}" >> $GITHUB_ENV
- name: Convert repository name to lowercase
id: repo
run: echo "REPO_NAME=$(echo '${{ github.repository }}' | tr '[:upper:]' '[:lower:]')" >> $GITHUB_ENV
- name: Build Docker image
run: |
docker build -t ghcr.io/${{ env.REPO_NAME }}:${{ env.VERSION }} .
docker tag ghcr.io/${{ env.REPO_NAME }}:${{ env.VERSION }} ghcr.io/${{ env.REPO_NAME }}:latest
- name: Push Docker image
run: |
docker push ghcr.io/${{ env.REPO_NAME }}:${{ env.VERSION }}
docker push ghcr.io/${{ env.REPO_NAME }}:latest