Skip to content

Commit

Permalink
Switch to CI_ENVIRONMENT_SLUG for env name
Browse files Browse the repository at this point in the history
  • Loading branch information
galexrt committed Jun 24, 2018
1 parent 808a87e commit 5ac1f7e
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 24 deletions.
22 changes: 11 additions & 11 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,11 @@ image_build:
- docker:dind
script:
- docker info
- docker login -u ${CI_REGISTRY_USER} -p ${CI_REGISTRY_PASSWORD} ${CI_REGISTRY}
- docker build -t ${CI_REGISTRY_IMAGE}:latest .
- docker tag ${CI_REGISTRY_IMAGE}:latest ${CI_REGISTRY_IMAGE}:${CI_COMMIT_REF_NAME}
- test ! -z "${CI_COMMIT_TAG}" && docker push ${CI_REGISTRY_IMAGE}:latest
- docker push ${CI_REGISTRY_IMAGE}:${CI_COMMIT_REF_NAME}
- docker login -u "${CI_REGISTRY_USER}" -p "${CI_REGISTRY_PASSWORD}" "${CI_REGISTRY}"
- docker build -t "${CI_REGISTRY_IMAGE}:latest" .
- docker tag "${CI_REGISTRY_IMAGE}:latest" "${CI_REGISTRY_IMAGE}:${CI_COMMIT_REF_NAME}"
- test ! -z "${CI_COMMIT_TAG}" && docker push "${CI_REGISTRY_IMAGE}:latest"
- docker push "${CI_REGISTRY_IMAGE}:${CI_COMMIT_REF_NAME}"

deploy_review:
image: lachlanevenson/k8s-kubectl:latest
Expand All @@ -75,12 +75,12 @@ deploy_review:
- tags
environment:
name: review/$CI_BUILD_REF_NAME
url: https://$CI_BUILD_REF_SLUG-presentation-gitlab-k8s.edenmal.net
url: https://$CI_ENVIRONMENT_SLUG-presentation-gitlab-k8s.edenmal.net
on_stop: stop_review
script:
- kubectl version
- cd manifests/
- sed -i "s/__CI_BUILD_REF_SLUG__/${CI_BUILD_REF_SLUG}/" deployment.yaml ingress.yaml service.yaml
- sed -i "s/__CI_ENVIRONMENT_SLUG__/${CI_ENVIRONMENT_SLUG}/" deployment.yaml ingress.yaml service.yaml
- sed -i "s/__VERSION__/${CI_COMMIT_REF_NAME}/" deployment.yaml ingress.yaml service.yaml
- |
if kubectl apply -f deployment.yaml | grep -q unchanged; then
Expand All @@ -92,7 +92,7 @@ deploy_review:
- kubectl apply -f service.yaml || true
- kubectl apply -f ingress.yaml
- kubectl rollout status -f deployment.yaml
- kubectl get all,ing -l app=${CI_BUILD_REF_SLUG}
- kubectl get all,ing -l app=${CI_ENVIRONMENT_SLUG}

stop_review:
image: lachlanevenson/k8s-kubectl:latest
Expand All @@ -110,8 +110,8 @@ stop_review:
action: stop
script:
- kubectl version
- kubectl delete ing -l app=${CI_BUILD_REF_SLUG}
- kubectl delete all -l app=${CI_BUILD_REF_SLUG}
- kubectl delete ing -l app=${CI_ENVIRONMENT_SLUG}
- kubectl delete all -l app=${CI_ENVIRONMENT_SLUG}

deploy_live:
image: lachlanevenson/k8s-kubectl:latest
Expand All @@ -125,7 +125,7 @@ deploy_live:
script:
- kubectl version
- cd manifests/
- sed -i "s/__CI_BUILD_REF_SLUG__/${CI_ENVIRONMENT_SLUG}/" deployment.yaml ingress.yaml service.yaml
- sed -i "s/__CI_ENVIRONMENT_SLUG__/${CI_ENVIRONMENT_SLUG}/" deployment.yaml ingress.yaml service.yaml
- sed -i "s/__VERSION__/${CI_COMMIT_REF_NAME}/" deployment.yaml ingress.yaml service.yaml
- kubectl apply -f deployment.yaml
- kubectl apply -f service.yaml
Expand Down
2 changes: 1 addition & 1 deletion manifests/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
This directory contains the actual manifests used to deploy the built Docker image to Kubernetes.
The manifests contain placeholders (like `__CI_BUILD_REF_SLUG__`) which are replaced by the GitLab CI pipeline.
The manifests contain placeholders (like `__CI_ENVIRONMENT_SLUG__`) which are replaced by the GitLab CI pipeline.

For more information, see the repo root [README.md](../README.md) and the [.gitlab-ci.yml](../.gitlab-ci.yml).
8 changes: 4 additions & 4 deletions manifests/deployment.yaml
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: __CI_BUILD_REF_SLUG__
name: __CI_ENVIRONMENT_SLUG__
labels:
app: __CI_BUILD_REF_SLUG__
app: __CI_ENVIRONMENT_SLUG__
track: stable
spec:
replicas: 2
selector:
matchLabels:
app: __CI_BUILD_REF_SLUG__
app: __CI_ENVIRONMENT_SLUG__
template:
metadata:
labels:
app: __CI_BUILD_REF_SLUG__
app: __CI_ENVIRONMENT_SLUG__
track: stable
spec:
imagePullSecrets:
Expand Down
10 changes: 5 additions & 5 deletions manifests/ingress.yaml
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: presentation-gitlab-k8s-__CI_BUILD_REF_SLUG__
name: presentation-gitlab-k8s-__CI_ENVIRONMENT_SLUG__
namespace: presentation-gitlab-k8s
labels:
app: __CI_BUILD_REF_SLUG__
app: __CI_ENVIRONMENT_SLUG__
annotations:
kubernetes.io/tls-acme: "true"
kubernetes.io/ingress.class: "nginx"
spec:
tls:
- hosts:
- __CI_BUILD_REF_SLUG__-presentation-gitlab-k8s.edenmal.net
- __CI_ENVIRONMENT_SLUG__-presentation-gitlab-k8s.edenmal.net
# the secret used here is an unsigned wildcard cert for demo purposes
# use your own or comment this out
secretName: tls-wildcard-demo
rules:
- host: __CI_BUILD_REF_SLUG__-presentation-gitlab-k8s.edenmal.net
- host: __CI_ENVIRONMENT_SLUG__-presentation-gitlab-k8s.edenmal.net
http:
paths:
- path: /
backend:
serviceName: presentation-gitlab-k8s-__CI_BUILD_REF_SLUG__
serviceName: presentation-gitlab-k8s-__CI_ENVIRONMENT_SLUG__
servicePort: 8000
6 changes: 3 additions & 3 deletions manifests/service.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
apiVersion: v1
kind: Service
metadata:
name: presentation-gitlab-k8s-__CI_BUILD_REF_SLUG__
name: presentation-gitlab-k8s-__CI_ENVIRONMENT_SLUG__
namespace: presentation-gitlab-k8s
labels:
app: __CI_BUILD_REF_SLUG__
app: __CI_ENVIRONMENT_SLUG__
annotations:
prometheus.io/scrape: "true"
prometheus.io/port: "8000"
Expand All @@ -17,4 +17,4 @@ spec:
port: 8000
protocol: TCP
selector:
app: __CI_BUILD_REF_SLUG__
app: __CI_ENVIRONMENT_SLUG__

0 comments on commit 5ac1f7e

Please sign in to comment.