-
Notifications
You must be signed in to change notification settings - Fork 0
108 lines (103 loc) · 3.2 KB
/
Copy pathbuild-docker.yml
File metadata and controls
108 lines (103 loc) · 3.2 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# -*- coding: utf-8 -*-
# vim: ft=yaml
# yamllint disable rule:truthy
# yamllint disable rule:line-length
---
on:
workflow_call:
inputs:
docker-registry:
description: Docker registry to push to
required: false
type: string
default: ghcr.io
repository:
description: Docker repository
required: false
type: string
default: ${{ github.repository }}
docker-registry-username:
description: Docker registry username
required: false
type: string
default: ${{ github.actor }}
context:
description: Docker build context
required: false
type: string
default: .
dockerfile:
description: Dockerfile to build
required: false
type: string
default: ./build/app/Dockerfile
target:
description: Docker build target
required: false
type: string
default: null
push:
description: Push to registry
required: false
type: boolean
default: true
version:
description: Docker image version
required: true
type: string
tags:
description: Docker image tags
required: false
type: string
default: "latest"
runs-on:
description: Select github runner based on labels, default is "['ubuntu-latest']"
required: false
type: string
default: "['ubuntu-latest']"
secrets:
docker-registry-password:
description: Docker registry password
required: true
permissions:
contents: read
packages: write
jobs:
build-and-push:
runs-on: ${{ fromJson(inputs.runs-on) }}
steps:
- uses: actions/checkout@v5
with:
fetch-depth: 0
- name: Login to docker registry
uses: docker/login-action@v3
with:
registry: ${{ inputs.docker-registry }}
username: ${{ inputs.docker-registry-username }}
password: ${{ secrets.docker-registry-password }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- id: set-repo-name
run: |
REPO_NAME="${{ inputs.docker-registry }}/$(echo "${{ inputs.repository }}" | tr '[:upper:]' '[:lower:]')"
echo "repo_name=$REPO_NAME" >> $GITHUB_ENV
- name: Build the Docker image
uses: docker/build-push-action@v6
with:
context: ${{ inputs.context }}
file: ${{ inputs.dockerfile }}
target: ${{ inputs.target }}
push: ${{ inputs.push }}
no-cache: true
tags: ${{ env.repo_name }}:${{ inputs.version }}
- name: Tag and push
run: |
tags="${{ inputs.tags }}"
echo "Tagging and publishing ${{ env.repo_name }}:${{ inputs.version }} with tags: $tags"
IFS=',' read -ra tags_array <<< "$tags"
docker pull ${{ env.repo_name }}:${{ inputs.version }}
for tag in "${tags_array[@]}"; do
tag=$(echo $tag | xargs) # Trim any leading/trailing whitespace
docker tag ${{ env.repo_name }}:${{ inputs.version }} ${{ env.repo_name }}:$tag
docker push ${{ env.repo_name }}:$tag
done