/
cloudbuild.yaml
100 lines (100 loc) · 3.1 KB
/
cloudbuild.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
93
94
95
96
97
98
99
100
steps:
- name: 'gcr.io/cloud-builders/gcloud'
entrypoint: 'sh'
args:
- '-c'
- |
cat <<EOF > src/environments/environment.qa.ts
export const environment = {
production: true,
stsServer: '$_STS_SERVER',
serverUrl: '$_API_SERVER',
storageUrl: 'https://storage.googleapis.com/oos-images-63325/'
};
EOF
# Build the container image
- name: 'gcr.io/k8s-skaffold/pack'
entrypoint: 'pack'
args:
- build
- ${_REGION}-docker.pkg.dev/$PROJECT_ID/outofschool/oos-frontend:$SHORT_SHA
- --cache-image=${_REGION}-docker.pkg.dev/$PROJECT_ID/outofschool/oos-cache:front
- --builder=paketobuildpacks/builder:base
- --buildpack=paketo-buildpacks/web-servers
- --buildpack=gcr.io/paketo-buildpacks/environment-variables
- --env=BP_NODE_RUN_SCRIPTS=build:qa
- --env=BPE_APP_ROOT=/workspace
- --env=BP_INCLUDE_FILES=dist/out-of-school/*:nginx.conf:includes/*
- --publish
##### Update the tag #####
# Access the SSH key from Secret Manager
- name: gcr.io/cloud-builders/gcloud
entrypoint: 'bash'
args:
- '-c'
- |
cat <<EOF > /root/.ssh/id_github
$$SSH
EOF
secretEnv: ['SSH']
volumes:
- name: 'ssh'
path: /root/.ssh
# Set up git with key and domain
- name: 'gcr.io/cloud-builders/git'
entrypoint: 'bash'
args:
- '-c'
- |
chmod 600 /root/.ssh/id_github
cat <<EOF >/root/.ssh/config
Hostname github.com
IdentityFile /root/.ssh/id_github
EOF
ssh-keyscan -t rsa github.com > /root/.ssh/known_hosts
volumes:
- name: 'ssh'
path: /root/.ssh
# Increment tag
- name: gcr.io/cloud-builders/git
entrypoint: 'bash'
args:
- '-c'
- |
git config --global user.name cloudbuild
git config --global user.email oos@cloudbuild.gserviceaccount.com
echo "Cloning repo"
git clone --branch $BRANCH_NAME git@github.com:ita-social-projects/OoS-Frontend.git
cd OoS-Frontend
CURRENT_VERSION=`git describe --tags $$(git rev-list --tags --max-count=1) 2>/dev/null`
if [[ $$CURRENT_VERSION == '' ]]
then
CURRENT_VERSION='gcp-0.0.0'
fi
echo "Current Version: $$CURRENT_VERSION"
CURRENT_VERSION_PARTS=($${CURRENT_VERSION//./ })
VNUM1=$${CURRENT_VERSION_PARTS[0]}
VNUM2=$${CURRENT_VERSION_PARTS[1]}
VNUM3=$${CURRENT_VERSION_PARTS[2]}
VNUM3=$$((VNUM3+1))
NEW_TAG="$$VNUM1.$$VNUM2.$$VNUM3"
echo "Updating $$CURRENT_VERSION to $$NEW_TAG"
GIT_COMMIT=`git rev-parse HEAD`
NEEDS_TAG=`git describe --contains $$GIT_COMMIT 2>/dev/null`
if [ -z "$$NEEDS_TAG" ]; then
DESCRIPTION=`git log --cherry --pretty=format:'▪ %s by %an' --max-count=1`
git tag -a $$NEW_TAG -m "$$DESCRIPTION"
echo "Tagged with $$NEW_TAG"
git push --tags
else
echo "Already a tag on this commit"
fi
volumes:
- name: 'ssh'
path: /root/.ssh
availableSecrets:
secretManager:
- versionName: $_GITHUB_DEPLOY
env: 'SSH'
options:
logging: CLOUD_LOGGING_ONLY