-
Notifications
You must be signed in to change notification settings - Fork 0
/
action.yml
65 lines (57 loc) · 2.12 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
name: "Release Docker Image to GCP Artifact Registry"
description: "GitHub Action to build a Docker image and push it to GCP Artifact Registry."
inputs:
gcp_artifact_registry:
description: GCP_ARTIFACT_REGISTRY
required: true
gcp_project_id:
description: GCP_PROJECT_ID
required: true
gcp_region:
description: GCP_REGION
required: true
gcp_service_account_email:
description: GCP_SERVICE_ACCOUNT_EMAIL
required: true
gcp_workload_identity_provider:
description: GCP_WORKLOAD_IDENTITY_PROVIDER
required: true
image_tag:
description: IMAGE_TAG
required: true
slack_webhook_url:
description: "SLACK_WEBHOOK_URL"
required: false
default: ""
runs:
using: "composite"
steps:
- name: 'Checkout'
uses: actions/checkout@v4
- name: 'Authenticate to Google Cloud'
uses: 'google-github-actions/auth@v1'
with:
workload_identity_provider: ${{ inputs.gcp_workload_identity_provider }}
service_account: ${{ inputs.gcp_service_account_email }}
- name: 'Setup Google Cloud CLI'
uses: 'google-github-actions/setup-gcloud@v1'
with:
version: '>= 421.0.0'
- name: 'Add Artifact Registry to Docker'
run: 'gcloud auth configure-docker ${{ inputs.gcp_region }}-docker.pkg.dev'
shell: bash
- name: 'Build Docker image and push to Artifact Registry'
env:
IMAGE_PATH: '${{ inputs.gcp_region }}-docker.pkg.dev/${{ inputs.gcp_project_id }}/${{ inputs.gcp_artifact_registry }}/${{ github.event.repository.owner.login }}/${{ github.event.repository.name }}'
IMAGE_TAG: '${{ inputs.image_tag }}'
run: |
docker build --build-arg APP_VERSION=${IMAGE_TAG} -t ${IMAGE_PATH,,}:${IMAGE_TAG} .
docker push ${IMAGE_PATH,,}:${IMAGE_TAG}
shell: bash
- name: Notify slack
if: ${{ inputs.slack_webhook_url != '' }}
env:
MESSAGE: "${{ github.event.repository.owner.login }}/${{ github.event.repository.name }}:${{ inputs.image_tag }} has been pushed to GCP Artifact Registry"
run: |
curl -X POST -H 'Content-type: application/json' --data "{\"text\":\"${MESSAGE}\"}" ${{ inputs.slack_webhook_url }}
shell: bash