Commit f31ae93d authored by echel0n's avatar echel0n
Browse files

Updated gitlab ci/cd script allowing reviews

parent 855fbd73
before_script:
- apk add --no-cache py-pip
stages:
- release
- build
- review
- deploy
variables:
DOCKER_DRIVER: overlay2
DOCKER_HOST: tcp://localhost:2375
DOCKER_TLS_CERTDIR: ""
services:
- docker:dind
sentry_release_master:
stage: release
image:
......@@ -53,10 +44,79 @@ sentry_release_develop:
- branches
- triggers
build:mr:
stage: build
image:
name: docker:latest
entrypoint: ["/bin/sh", "-c"]
variables:
DOCKER_DRIVER: overlay2
DOCKER_HOST: tcp://localhost:2375
DOCKER_TLS_CERTDIR: ""
services:
- docker:dind
script:
- docker login -u "${CI_REGISTRY_USER}" -p "${CI_REGISTRY_PASSWORD}" "${CI_REGISTRY}"
- docker build --network host -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}"
only:
- merge_requests
deploy:mr:
stage: review
dependencies:
- build:mr
image:
name: lachlanevenson/k8s-kubectl:latest
entrypoint: ["/bin/sh", "-c"]
script:
- kubectl create secret --namespace=${KUBE_NAMESPACE} docker-registry gitlab-registry --docker-server=${CI_REGISTRY} --docker-username=${CI_REGISTRY_USER} --docker-password=${CI_JOB_TOKEN} --docker-email=$GITLAB_USER_EMAIL || true
- sed -i "s~__CI_REGISTRY_IMAGE__~${CI_REGISTRY_IMAGE}~" manifests/deployment.yaml
- sed -i "s/__VERSION__/${CI_COMMIT_REF_NAME}/" manifests/deployment.yaml manifests/ingress.yaml manifests/service.yaml
- sed -i "s/__CI_COMMIT_REF_SLUG__/${CI_COMMIT_REF_SLUG}/" manifests/deployment.yaml manifests/ingress.yaml manifests/service.yaml
- sed -i "s/__CI_ENVIRONMENT_SLUG__/${CI_ENVIRONMENT_SLUG}/" manifests/deployment.yaml manifests/ingress.yaml manifests/service.yaml
- sed -i "s/__KUBE_NAMESPACE__/${KUBE_NAMESPACE}/" manifests/deployment.yaml manifests/ingress.yaml manifests/service.yaml
- |
if kubectl apply -f manifests/deployment.yaml | grep -q unchanged; then
echo "=> Patching deployment to force image update."
kubectl patch -f manifests/deployment.yaml -p "{\"spec\":{\"template\":{\"metadata\":{\"annotations\":{\"ci-last-updated\":\"$(date +'%s')\"}}}}}"
else
echo "=> Deployment apply has changed the object, no need to force image update."
fi
- kubectl apply -f manifests/service.yaml || true
- kubectl apply -f manifests/ingress.yaml
- kubectl rollout status -f manifests/deployment.yaml
environment:
name: review/$CI_COMMIT_REF_NAME
url: https://review.sickrage.ca/$CI_COMMIT_REF_SLUG
on_stop: stop:mr
only:
- merge_requests
stop:mr:
stage: review
image:
name: lachlanevenson/k8s-kubectl:latest
entrypoint: ["/bin/sh", "-c"]
script:
- kubectl delete ing -l ref=${CI_ENVIRONMENT_SLUG}
- kubectl delete all -l ref=${CI_ENVIRONMENT_SLUG}
variables:
GIT_STRATEGY: none
when: manual
environment:
name: review/$CI_COMMIT_REF_NAME
action: stop
only:
- merge_requests
deploy_pypi:
stage: deploy
image: python:3.7-alpine3.9
script:
- apk add --no-cache py-pip
- pip install -U twine
- python setup.py sdist bdist_wheel
- twine upload dist/*
......
apiVersion: apps/v1
kind: Deployment
metadata:
name: __CI_COMMIT_REF_SLUG__
namespace: __KUBE_NAMESPACE__
labels:
app: __CI_COMMIT_REF_SLUG__
ref: __CI_ENVIRONMENT_SLUG__
spec:
replicas: 1
selector:
matchLabels:
app: __CI_COMMIT_REF_SLUG__
ref: __CI_ENVIRONMENT_SLUG__
template:
metadata:
labels:
app: __CI_COMMIT_REF_SLUG__
ref: __CI_ENVIRONMENT_SLUG__
spec:
containers:
- name: app
image: __CI_REGISTRY_IMAGE__:__VERSION__
imagePullPolicy: Always
env:
- name: TZ
value: "Canada/Pacific"
ports:
- containerPort: 8081
imagePullSecrets:
- name: gitlab-registry
\ No newline at end of file
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: __CI_COMMIT_REF_SLUG__
namespace: __KUBE_NAMESPACE__
labels:
app: __CI_COMMIT_REF_SLUG__
ref: __CI_ENVIRONMENT_SLUG__
annotations:
kubernetes.io/ingress.class: "nginx"
spec:
tls:
- hosts:
- review.sickrage.ca
secretName: sickrage-ca-tls
rules:
- host: review.sickrage.ca
http:
paths:
- path: /__CI_COMMIT_REF_SLUG__
backend:
serviceName: __CI_COMMIT_REF_SLUG__
servicePort: 80
\ No newline at end of file
apiVersion: v1
kind: Service
metadata:
name: __CI_COMMIT_REF_SLUG__
namespace: __KUBE_NAMESPACE__
labels:
app: __CI_COMMIT_REF_SLUG__
ref: __CI_ENVIRONMENT_SLUG__
spec:
type: ClusterIP
ports:
- port: 80
protocol: TCP
targetPort: 8081
selector:
app: __CI_COMMIT_REF_SLUG__
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment