-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaction.yml
66 lines (61 loc) · 1.87 KB
/
action.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
name: 'Docker Login Tag and Push'
description: 'Logs tags and pushes image into Registry'
inputs:
image:
description: 'Local image name. Assumes repository not present and tag present.'
required: true
repo:
description: 'Registry host name'
required: true
username:
description: 'Registry username'
required: true
password:
description: 'Registry password'
required: true
tag:
description: 'New tag if retagging is needed'
required: false
runs:
using: 'composite'
steps:
- name: Get new image name
id: new-image-name
uses: actions/github-script@v7
env:
repo: ${{ inputs.repo }}
tag: ${{ inputs.tag }}
image: ${{ inputs.image }}
with:
script: |
let { repo, tag, image } = process.env;
repo = repo ? repo + '/' : repo;
const fullName = image.split('/');
if (fullName.length == 2 && fullName[0].Contains('.')) image = fullName[1];
else if (fullName.length > 2) image = fullName.slice(-2).join('/');
if (tag) {
const arr=image.split(':');
arr[arr.length - 1]=tag;
core.setOutput('image', repo+arr.join(':'));
} else {
core.setOutput('image', repo+image);
}
- name: Docker Login
if: inputs.repo == ''
uses: docker/login-action@v3
with:
username: ${{ inputs.username }}
password: ${{ inputs.password }}
- name: Login
if: inputs.repo != ''
uses: docker/login-action@v3
with:
registry: ${{ inputs.repo}}
username: ${{ inputs.username }}
password: ${{ inputs.password }}
- name: Tag and Push
id: tag-push
shell: bash
run: |
docker tag ${{ inputs.image }} ${{ steps.new-image-name.outputs.image }}
docker push ${{ steps.new-image-name.outputs.image }}