-
Notifications
You must be signed in to change notification settings - Fork 103
/
Copy pathsuperblocks.yaml
77 lines (73 loc) · 4.21 KB
/
superblocks.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
# Vanilla configuration
# Start with a minimal configuration that you can customize to build your code
# http://superblocks.com/docs/configuration/configuration-introduction/#section=configuration
version: 1
jobs:
push_to_docker_registry:
image: docker:18.09.7
services:
- docker:18.09.7-dind
script:
- echo "$GITHUB_REGISTRY_TOKEN" | docker login docker.pkg.github.com --username $GITHUB_REGISTRY_USER --password-stdin
- docker build --build-arg BUILD=build -t $GITHUB_REGISTRY_IMAGE:$SUPER_COMMIT_SHA1 .
- docker push $GITHUB_REGISTRY_IMAGE:$SUPER_COMMIT_SHA1
deploy_to_staging:
image: alpine
script:
- apk add --no-cache curl
- curl -LO https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl
- chmod +x ./kubectl
- mv ./kubectl /usr/local/bin/kubectl
- kubectl config set-cluster $K8S_CLUSTER_NAME --server=$K8S_SERVER --insecure-skip-tls-verify=true
- kubectl config set clusters.k8s.certificate-authority-data $K8S_CERTIFICATE_AUTHORITY_DATA
- kubectl config set-credentials $K8S_USER_NAME --token=$K8S_USER_TOKEN
- kubectl config set-context staging --cluster=$K8S_CLUSTER_NAME --user=$K8S_USER_NAME --namespace=staging
- kubectl config use-context staging
- 'printf "apiVersion: v1\nkind: Secret\n$(kubectl create secret docker-registry $CI_PROJECT_NAME-github-registry --docker-server=$CI_REGISTRY --docker-username=$GITHUB_REGISTRY_USER --docker-password=$GITHUB_REGISTRY_TOKEN -o yaml --dry-run)" | kubectl apply -f -'
# pass env variables, which names start with "STAGING_" to application running in kubernetes
- env | sed -n "s/^STAGING_\(.*\)$/\1/p" > k8s_prefixed_variables
- 'printf "apiVersion: v1\nkind: Secret\n$(kubectl create secret generic $CI_PROJECT_NAME-secret --from-env-file k8s_prefixed_variables -o yaml --dry-run)" | kubectl apply -f -'
- rm k8s_prefixed_variables
# generate deployment file
- sed 's _APP_NAME_ '"$CI_PROJECT_NAME"' g; s _CONTAINER_IMAGE_ '"$GITHUB_REGISTRY_IMAGE:$SUPER_COMMIT_SHA1"' g' kubernetes.tpl.yml > kubernetes.yml;
- kubectl apply -f kubernetes.yml\
deploy_to_prod:
image: alpine
script:
- apk add --no-cache curl
- curl -LO https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl
- chmod +x ./kubectl
- mv ./kubectl /usr/local/bin/kubectl
- kubectl config set-cluster $K8S_CLUSTER_NAME --server=$K8S_SERVER --insecure-skip-tls-verify=true
- kubectl config set clusters.k8s.certificate-authority-data $K8S_CERTIFICATE_AUTHORITY_DATA
- kubectl config set-credentials $K8S_USER_NAME --token=$K8S_USER_TOKEN
- kubectl config set-context prodution --cluster=$K8S_CLUSTER_NAME --user=$K8S_USER_NAME
- kubectl config use-context prodution
- 'printf "apiVersion: v1\nkind: Secret\n$(kubectl create secret docker-registry $CI_PROJECT_NAME-github-registry --docker-server=$CI_REGISTRY --docker-username=$GITHUB_REGISTRY_USER --docker-password=$GITHUB_REGISTRY_TOKEN -o yaml --dry-run)" | kubectl apply -f -'
# pass env variables, which names start with "PROD_" to application running in kubernetes
- env | sed -n "s/^PROD_\(.*\)$/\1/p" > k8s_prefixed_variables
- 'printf "apiVersion: v1\nkind: Secret\n$(kubectl create secret generic $CI_PROJECT_NAME-secret --from-env-file k8s_prefixed_variables -o yaml --dry-run)" | kubectl apply -f -'
- rm k8s_prefixed_variables
# generate deployment file
- sed 's _APP_NAME_ '"$CI_PROJECT_NAME"' g; s _CONTAINER_IMAGE_ '"$GITHUB_REGISTRY_IMAGE:$SUPER_COMMIT_SHA1"' g' kubernetes.tpl.yml > kubernetes.yml;
- kubectl apply -f kubernetes.yml
stages:
- build:
jobs:
- push_to_docker_registry:
filters:
only:
- master
- deploy_staging:
jobs:
- deploy_to_staging:
filters:
only:
- master
- deploy_prod:
jobs:
- deploy_to_prod:
when: manual
filters:
only:
- master