-
Notifications
You must be signed in to change notification settings - Fork 2
84 lines (73 loc) · 2.84 KB
/
push_to_private.yml
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
name: Push container to harbor registry
on:
workflow_call:
inputs:
build-args:
type: string
default: ""
description: Build args to pass to docker build A=a B=b ...
required: false
image_name:
type: string
description: Image name to push to registry (w/o tag and host)
required: true
tag:
type: string
description: Tag to push to registry
required: true
context:
type: string
default: "."
description: Context to build from
required: true
dockerfile:
type: string
default: ${{ inputs.context }}/Dockerfile
description: Dockerfile to build
registry_host:
type: string
description: Docker registry host
required: false
default: "harbor.dev.agrold.org"
secrets:
DOCKER_REGISTRY_USER:
description: Docker username
required: true
DOCKER_REGISTRY_PASSWORD:
description: Docker password
required: true
run-name: Push ${{ github.repository }} to private registry with tag ${{ inputs.tag}}
jobs:
job:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Normalize build args
id: normalize_build_args
# the input.build-args is a string line in the form A=a,B=b c,D=d,... we want to convert it to a list of strings
run: |
args="$(echo '${{ inputs.build-args }}' | tr ',' '\n')"
echo "args=$args" >> $GITHUB_OUTPUT
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3.3.0
with:
version: latest
- name: "Login to registry at: ${{ inputs.registry_host }}"
uses: docker/login-action@v3.2.0
with:
registry: ${{ inputs.registry_host }}
username: ${{ secrets.DOCKER_REGISTRY_USER }}
password: ${{ secrets.DOCKER_REGISTRY_PASSWORD }}
- name: Build and push Docker image ${{ inputs.registry_host }}/${{ inputs.image_name }}:${{ inputs.tag }}
run: |
cd ${{ inputs.context }}
docker build . --build-arg ${{ steps.normalize_build_args.outputs.args }} -t ${{ inputs.registry_host }}/${{ inputs.image_name }}:${{ inputs.tag }} -t ${{ inputs.registry_host }}/${{ inputs.image_name }}:latest
docker push ${{ inputs.registry_host }}/${{ inputs.image_name }}:${{ inputs.tag }}
docker push ${{ inputs.registry_host }}/${{ inputs.image_name }}:latest
# uses: docker/build-push-action@v6.3.0
# with:
# build-args: ${{ steps.normalize_build_args.outputs.args }}
# push: true
# context: ${{ inputs.context }}
# file: ${{ inputs.dockerfile }}
# tags: ${{ inputs.registry_host }}/${{ inputs.image_name }}:${{ inputs.tag }},${{ inputs.registry_host }}/${{ inputs.image_name }}:latest