-
Notifications
You must be signed in to change notification settings - Fork 0
174 lines (142 loc) · 6.44 KB
/
gcp-cloud-deploy.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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
name: 'Brightspot GCP Deploy'
on:
workflow_call:
inputs:
project:
description: 'Shortname for project'
required: true
type: string
registry:
description: 'GCP registry to push the build to'
required: true
type: string
repository:
description: 'Repository name. This overrides the default which is ${project}/${project}'
required: false
type: string
docker-image-name:
description: 'The docker image name to be created for this build. This overrides the default which is ${repository}'
required: false
type: string
dockerfile-directory:
description: 'Directory containing Dockerfile for deploy. Defaults to etc/container'
required: false
type: string
default: 'etc/container'
gcloud-version:
description: "The version of gcloud to be installed. Default is 'latest'. Can be set to value by specying the version like '= 417.0.1' for exact match or '>= 417.0.1' for anything above this version match"
required: false
type: string
default: 'latest'
runs-on:
description: Platform to execute on
type: string
default: ubuntu-20.04-4core
override-build-name:
description: Forces the docker image build and tag name to the given value.
required: false
type: string
secrets:
GCP_GCR_SECRET_KEY:
required: true
jobs:
build:
name: "GCP Cloud Deploy"
runs-on: ${{ inputs.runs-on }}
env:
opsdesk_api_client_id: ${{ secrets.OPSDESK_API_CLIENT_ID }}
# Map the job outputs to step outputs
outputs:
container-build-tag: ${{ steps.build-container.outputs.container-build-tag }}
container-version-tag: ${{ steps.build-container.outputs.container-version-tag }}
caller-sha: ${{ steps.workflows-version.outputs.caller-sha }}
steps:
- uses: actions/checkout@v4
- uses: actions/download-artifact@v4
with:
name: brightspot-build
path: brightspot-build
- name: Get workflow reference
id: workflow-version
run: |
sha=$(curl -L -H "Accept: application/vnd.github+json" -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" -H "X-GitHub-Api-Version: 2022-11-28" https://api.github.com/repos/${{ github.repository }}/actions/runs/${{ github.run_id }} | jq -r '.referenced_workflows[] | select(.path|contains("gcp-cloud-deploy")) | .sha')
echo "caller-sha=$sha" >> $GITHUB_OUTPUT
- uses: actions/checkout@v4
with:
repository: perfectsense/brightspot-github-actions-workflows
ref: ${{ steps.workflow-version.outputs.caller-sha }}
path: ./brightspot
- name: Get Tag Version
shell: bash
run: |
echo "GITHUB_ACTIONS_TAG=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV
echo "GITHUB_ACTIONS_PULL_REQUEST=${{ github.event.pull_request.number }}" >> $GITHUB_ENV
- name: Set Up gcloud CLI
uses: google-github-actions/auth@v2
with:
credentials_json: ${{ secrets.GCP_GCR_SECRET_KEY }}
- name: Set up Cloud SDK
uses: google-github-actions/setup-gcloud@v2
with:
version: "${{ inputs.gcloud-version }}"
# Configure docker to use the gcloud command-line tool as a credential helper
- name: Configure docker
shell: bash
run: |
# Set up docker to authenticate
# via gcloud command-line tool.
gcloud auth configure-docker ${{ inputs.registry }}
- name: Docker test
shell: bash
run: |
gcloud artifacts docker images list ${{ inputs.registry }}/${{ inputs.project }}/${{ inputs.repository }}
- name: Build Container
id: build-container
shell: bash
run: |
version=""
build=""
echo "GITHUB_ACTIONS_TAG ${GITHUB_ACTIONS_TAG}"
echo "GITHUB_ACTIONS_PULL_REQUEST ${GITHUB_ACTIONS_PULL_REQUEST}"
if [[ ! -z "${{ inputs.override-build-name }}" ]]; then
echo "Override Build Name ${{ inputs.override-build-name }}"
version="${{ inputs.override-build-name }}"
build="${{ inputs.override-build-name }}"
elif [[ ! -z "$GITHUB_ACTIONS_PULL_REQUEST" && "$GITHUB_ACTIONS_PULL_REQUEST" != "" ]]; then
version="pullrequest-$GITHUB_ACTIONS_PULL_REQUEST"
build=pullrequest-$GITHUB_ACTIONS_PULL_REQUEST-build$GITHUB_RUN_NUMBER
elif [[ "$GITHUB_ACTIONS_TAG" =~ ^v[0-9]+\. ]]; then
echo "GITHUB_ACTIONS_TAG ${GITHUB_ACTIONS_TAG}"
version=release-${GITHUB_ACTIONS_TAG/v/}
build=release-${GITHUB_ACTIONS_TAG/v/}
else
COMMIT_COUNT=$(git rev-list --count HEAD)
COMMIT_SHA=$(git rev-parse --short=6 HEAD)
build=development-$(git describe --all | sed 's/heads\///' | sed 's/\//-/g')
build+=-build$GITHUB_RUN_NUMBER
version=development-$(git describe --all | sed 's/heads\///' | sed 's/\//-/g')
fi
cp brightspot-build/*.war ${{ inputs.dockerfile-directory }}/web.war
cd ${{ inputs.dockerfile-directory }}
PROJECT="${{ inputs.project }}"
REPOSITORY="${{ inputs.repository }}"
if [ -z ${REPOSITORY} ]; then
REPOSITORY="$PROJECT/$PROJECT"
fi
REGISTRY="${{ inputs.registry }}"
IMAGE_NAME="${{ inputs.docker-image-name }}"
if [ -z ${IMAGE_NAME} ]; then
IMAGE_NAME="$REPOSITORY"
fi
BUILD_TAG="$REGISTRY/$PROJECT/$REPOSITORY/$IMAGE_NAME:$build"
VERSION_TAG="$REGISTRY/$PROJECT/$REPOSITORY/$IMAGE_NAME:$version"
docker buildx build --push --build-arg WAR_ARTIFACT=web.war -t $VERSION_TAG -t $BUILD_TAG -f Dockerfile --metadata-file docker-metadata.json .
echo "container-build-tag=$(echo $BUILD_TAG)" >> $GITHUB_OUTPUT
echo "container-version-tag=$(echo $VERSION_TAG)" >> $GITHUB_OUTPUT
- uses: actions/download-artifact@v4
with:
name: brightspot-version
path: brightspot-version
- name: Upload Brightspot version
run: ./brightspot/analysis/opsdesk-post.sh brightspot-version/brightspot-version.txt ./${{ inputs.dockerfile-directory }}/docker-metadata.json ${{ secrets.OPSDESK_API_CLIENT_ID }} ${{ secrets.OPSDESK_API_SECRET }}
shell: bash