-
Notifications
You must be signed in to change notification settings - Fork 1
65 lines (63 loc) · 2.13 KB
/
publish-docker-image.yml
File metadata and controls
65 lines (63 loc) · 2.13 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
name: Publish docker image
on:
workflow_call:
inputs:
default-branch:
description: "Default branch name"
default: main
required: false
type: string
dockerfile-context:
description: "Relative path to Dockerfile"
required: false
type: string
default: "."
docker-tag:
description: "Docker image tag to use"
required: true
type: string
branch-tag:
description: "Branch tag to use for Docker image"
required: false
type: string
default: "latest"
secrets:
repo-token:
description: "GitHub token for release creation"
required: true
jobs:
publish-docker:
name: Publish Docker image
runs-on: ubuntu-22.04
steps:
- name: Checkout
uses: actions/checkout@v4
with:
ref: ${{ inputs.default_branch }}
- name: Set branch tag
run: |
if [ "${{ inputs.default_branch }}" == "main" ]; then
echo "branch_tag=latest" >> $GITHUB_ENV
elif [ "${{ inputs.default_branch }}" == "dev" ]; then
echo "branch_tag=dev" >> $GITHUB_ENV
else
echo "branch_tag=${{ inputs.branch-tag }}" >> $GITHUB_ENV
fi
echo "repo_owner=$(echo '${{ github.repository_owner }}' | tr '[:upper:]' '[:lower:]')" >> $GITHUB_ENV
echo "repo_name=$(echo '${{ github.event.repository.name }}' | tr '[:upper:]' '[:lower:]')" >> $GITHUB_ENV
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to Github Packages
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.repo-token }}
- name: Build and push image to GitHub Container Registry
uses: docker/build-push-action@v3
with:
context: ${{ inputs.dockerfile-context }}
push: true
tags: |
ghcr.io/${{ env.repo_owner }}/${{ env.repo_name }}:${{ inputs.docker-tag }}
ghcr.io/${{ env.repo_owner }}/${{ env.repo_name }}:${{ env.branch_tag }}