forked from semaphoreci-demos/semaphore-demo-javascript
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver-deploy-k8s.yml
72 lines (68 loc) · 2.92 KB
/
server-deploy-k8s.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
# This pipeline runs after docker-build.yml
version: v1.0
name: Deploy server to Kubernetes
agent:
machine:
type: e1-standard-2
os_image: ubuntu1804
blocks:
- name: Deploy server to Kubernetes
task:
# For info on creating secrets, see:
# https://docs.semaphoreci.com/article/66-environment-variables-and-secrets
secrets:
- name: gcr-secret
# Set environment variables that your project requires.
# See https://docs.semaphoreci.com/article/66-environment-variables-and-secrets
env_vars:
- name: CLUSTER_NAME
value: semaphore-demo-javascript-server
prologue:
commands:
# Authenticate using the file injected from the secret
- gcloud auth activate-service-account --key-file=.secrets.gcp.json
# Don't forget -q to silence confirmation prompts
- gcloud auth configure-docker -q
- gcloud config set project $GCP_PROJECT_ID
- gcloud config set compute/zone $GCP_PROJECT_DEFAULT_ZONE
# Get kubectl config file
- gcloud container clusters get-credentials $CLUSTER_NAME --zone $GCP_PROJECT_DEFAULT_ZONE --project $GCP_PROJECT_ID
- checkout
- cd src/server
jobs:
- name: Deploy
commands:
- kubectl get nodes
- kubectl get pods
# Our deployment.yml instructs Kubernetes to pull container image
# named semaphoredemos/semaphore-demo-javascript-server:$SEMAPHORE_WORKFLOW_ID
#
# envsubst is a tool which will replace $SEMAPHORE_WORKFLOW_ID with
# its current value. The same variable was used in server-docker-build.yml
# pipeline to tag and push a container image.
- envsubst < deployment.yml | tee helloWorld
- mv helloWorld deployment.yml
# Perform declarative deployment:
- kubectl apply -f deployment.yml
# If deployment to production succeeded, let's create a new version of
# our `latest` Docker image.
- name: Tag latest release
task:
secrets:
- name: gcr-secret
prologue:
commands:
# Authenticate using the file injected from the secret
- gcloud auth activate-service-account --key-file=.secrets.gcp.json
# Don't forget -q to silence confirmation prompts
- gcloud auth configure-docker -q
- gcloud config set project $GCP_PROJECT_ID
- gcloud config set compute/zone $GCP_PROJECT_DEFAULT_ZONE
- checkout
- cd src/server
jobs:
- name: docker tag latest
commands:
- docker pull "gcr.io/$GCP_PROJECT_ID/semaphore-demo-javascript-server:$SEMAPHORE_WORKFLOW_ID"
- docker tag "gcr.io/$GCP_PROJECT_ID/semaphore-demo-javascript-server:$SEMAPHORE_WORKFLOW_ID" "gcr.io/$GCP_PROJECT_ID/semaphore-demo-javascript-server:latest"
- docker push "gcr.io/$GCP_PROJECT_ID/semaphore-demo-javascript-server:latest"