-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaction.yaml
92 lines (84 loc) · 3.06 KB
/
action.yaml
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
name: 'Promote Container Image'
description: 'Promotes a container image'
inputs:
source_image_destination:
description: 'The destination of the source image'
required: true
target_image_destination:
description: 'The destination of the target image'
required: true
source_registry_url:
description: 'The source registry url'
required: true
target_registry_url:
description: 'The target registry url'
required: true
target_environment:
description: 'The target environment to promote the image to'
required: false
GCP_WORKLOAD_IDENTITY_PROVIDER:
description: 'The GCP workload identity provider for credential-less access'
required: true
GCP_SERVICE_ACCOUNT:
description: 'The GCP service account id for credential-less access'
required: true
SLACK_WEBHOOK_URL:
description: 'The Slack Webhook URL to send the notification to'
default: ''
required: false
SLACK_CHANNEL:
description: 'The Slack Channel to send the notification to'
required: false
runs:
using: "composite"
steps:
- id: 'auth'
name: 'Authenticate to Google Cloud'
uses: 'google-github-actions/auth@v0'
with:
create_credentials_file: false
token_format: 'access_token'
workload_identity_provider: ${{ inputs.GCP_WORKLOAD_IDENTITY_PROVIDER }}
service_account: ${{ inputs.GCP_SERVICE_ACCOUNT }}
- name: Login to Source Registry
uses: docker/login-action@v1
with:
registry: ${{ inputs.source_registry_url }}
username: oauth2accesstoken
password: ${{ steps.auth.outputs.access_token }}
- name: Login to Target Registry
if: inputs.target_registry_url != inputs.source_registry_url
uses: docker/login-action@v1
with:
registry: ${{ inputs.target_registry_url }}
username: oauth2accesstoken
password: ${{ steps.auth.outputs.access_token }}
- name: pull image
shell: bash
run: docker pull ${{ inputs.source_image_destination }}
- name: tag image
shell: bash
run: docker tag ${{ inputs.source_image_destination }} ${{ inputs.target_image_destination }}
- name: push image
shell: bash
run: docker push ${{ inputs.target_image_destination }}
- name: slackMessage
id: set_slack_message
shell: bash
run: |
if [ ! -z "$PR_TITLE" ]; then
echo "::set-output name=message::<$PR_URL|$PR_TITLE>"
else
echo "::set-output name=message::Image promotion for {{ inputs.target_environment }}"
fi
env:
PR_URL: ${{ github.event.pull_request.html_url }}
PR_TITLE: ${{ github.event.pull_request.title }}
- name: slack notify
if: inputs.SLACK_WEBHOOK_URL != ''
uses: rtCamp/[email protected]
env:
SLACK_CHANNEL: ${{ inputs.SLACK_CHANNEL }}
SLACK_WEBHOOK: ${{ inputs.SLACK_WEBHOOK_URL }}
SLACK_TITLE: Image ${{ inputs.target_image_destination }} promoted to ${{ inputs.target_environment }}
SLACK_MESSAGE: ${{ steps.set_slack_message.outputs.message }}