Skip to content

Commit

Permalink
Improved the GitLab CI dev and live stage
Browse files Browse the repository at this point in the history
Thanks to Levi Shawn Blaney for his comments on my blog post which
showed me how I could improve the GitLab CI files!

Updated Go vendor dependencies
  • Loading branch information
galexrt committed Jan 17, 2018
1 parent 235540f commit c4d97cb
Show file tree
Hide file tree
Showing 974 changed files with 176,362 additions and 8,296 deletions.
46 changes: 24 additions & 22 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ image: golang:1.8.3
# repository in /go/src/mydomainperso.com/repos/projectname
# Thus, making a symbolic link corrects this.
before_script:
- mkdir -p /go/src/gitlab.zerbytes.net/${CI_PROJECT_NAMESPACE}
- ln -sf ${CI_PROJECT_DIR} /go/src/gitlab.zerbytes.net/${CI_PROJECT_PATH}
- cd /go/src/gitlab.zerbytes.net/${CI_PROJECT_PATH}/
- mkdir -p /go/src/gitlab.edenmal.moe/${CI_PROJECT_NAMESPACE}
- ln -sf ${CI_PROJECT_DIR} /go/src/gitlab.edenmal.moe/${CI_PROJECT_PATH}
- cd /go/src/gitlab.edenmal.moe/${CI_PROJECT_PATH}/

stages:
- test
Expand Down Expand Up @@ -37,7 +37,7 @@ compile:
# Add here all the dependencies, or use glide/govendor/...
# to get them automatically.
# Better put this in a Makefile
- go build -race -ldflags "-X gitlab.zerbytes.net/${CI_PROJECT_PATH}/vendor/github.com/prometheus/common/version.Version=$VERSION -X gitlab.zerbytes.net/${CI_PROJECT_PATH}/vendor/github.com/prometheus/common/version.Revision=${CI_COMMIT_SHA} -X gitlab.zerbytes.net/${CI_PROJECT_PATH}/vendor/github.com/prometheus/common/version.Branch=${CI_COMMIT_REF_NAME} -X gitlab.zerbytes.net/${CI_PROJECT_PATH}/vendor/github.com/prometheus/common/version.BuildUser=$(whoami)@$(hostname) -X gitlab.zerbytes.net/${CI_PROJECT_PATH}/vendor/github.com/prometheus/common/version.BuildDate=$(date +%Y%m%d-%H:%M:%S) -extldflags '-static'" -o app
- go build -race -ldflags "-X gitlab.edenmal.moe/${CI_PROJECT_PATH}/vendor/github.com/prometheus/common/version.Version=$VERSION -X gitlab.edenmal.moe/${CI_PROJECT_PATH}/vendor/github.com/prometheus/common/version.Revision=${CI_COMMIT_SHA} -X gitlab.edenmal.moe/${CI_PROJECT_PATH}/vendor/github.com/prometheus/common/version.Branch=${CI_COMMIT_REF_NAME} -X gitlab.edenmal.moe/${CI_PROJECT_PATH}/vendor/github.com/prometheus/common/version.BuildUser=$(whoami)@$(hostname) -X gitlab.edenmal.moe/${CI_PROJECT_PATH}/vendor/github.com/prometheus/common/version.BuildDate=$(date +%Y%m%d-%H:%M:%S) -extldflags '-static'" -o app
artifacts:
paths:
- app
Expand All @@ -46,10 +46,10 @@ release_upload:
stage: release
image: minio/mc
script:
- echo "=> We already have artifact sotrage in GitLab! Are we sure we want this too?"
- mc config host add zerbytesnet https://s3.zerbytes.net ${ACCESS_KEY} ${SECRET_KEY} S3v4
- mc mb -p zerbytesnet/build-release-${CI_PROJECT_NAME}/
- mc cp app zerbytesnet/build-release-${CI_PROJECT_NAME}/
- echo "=> We already have artifact sotrage in GitLab! This is for demonstational purposes only."
- mc config host add edenmalmoe https://s3.edenmal.moe ${ACCESS_KEY} ${SECRET_KEY} S3v4
- mc mb -p edenmalmoe/build-release-${CI_PROJECT_NAME}/
- mc cp app edenmalmoe/build-release-${CI_PROJECT_NAME}/


image_build:
Expand All @@ -61,38 +61,40 @@ image_build:
- docker:dind
script:
- docker info
- docker login -u gitlab-ci-token -p ${CI_JOB_TOKEN} registry.zerbytes.net
- docker build -t registry.zerbytes.net/${CI_PROJECT_PATH}:latest .
- docker tag registry.zerbytes.net/${CI_PROJECT_PATH}:latest registry.zerbytes.net/${CI_PROJECT_PATH}:${CI_COMMIT_REF_NAME}
- test ! -z "${CI_COMMIT_TAG}" && docker push registry.zerbytes.net/${CI_PROJECT_PATH}:latest
- docker push registry.zerbytes.net/${CI_PROJECT_PATH}:${CI_COMMIT_REF_NAME}
- docker login -u gitlab-ci-token -p ${CI_JOB_TOKEN} registry.edenmal.moe
- docker build -t registry.edenmal.moe/${CI_PROJECT_PATH}:latest .
- docker tag registry.edenmal.moe/${CI_PROJECT_PATH}:latest registry.edenmal.moe/${CI_PROJECT_PATH}:${CI_COMMIT_REF_NAME}
- test ! -z "${CI_COMMIT_TAG}" && docker push registry.edenmal.moe/${CI_PROJECT_PATH}:latest
- docker push registry.edenmal.moe/${CI_PROJECT_PATH}:${CI_COMMIT_REF_NAME}

deploy_dev:
image: registry.gitlab.com/gitlab-examples/kubernetes-deploy
stage: deploy
environment:
name: dev
url: https://dev-presentation-gitlab-k8s.zerbytes.net
name: dev/${CI_COMMIT_REF_NAME}
url: https://dev-presentation-gitlab-k8s.edenmal.moe
script:
- echo "${KUBE_CA_PEM}" > kube_ca.pem
- kubectl config set-cluster default-cluster --server=${KUBE_URL} --certificate-authority="$(pwd)/kube_ca.pem"
- kubectl config set-credentials default-admin --token=${KUBE_TOKEN}
- kubectl config set-context default-system --cluster=default-cluster --user=default-admin --namespace ${KUBE_NAMESPACE}
- kubectl config use-context default-system
- kubectl cluster-info
- 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 cluster-info
- kubectl get deployments -l app=${CI_ENVIRONMENT_SLUG}
- kubectl create -f deployment.yaml || (kubectl delete -f deployment.yaml && kubectl apply -f deployment.yaml)
- kubectl create -f service.yaml || true
- |
test $(kubectl apply -f manifests/deployment.yml -n ${NAMESPACE}) == *"unchanged"* && \
kubectl patch deployment ${CI_ENVIRONMENT_SLUG} -p "{\"spec\":{\"template\":{\"metadata\":{\"annotations\":{\"ci-last-updated\":\"$(date +'%s')\"}}}}}"
- kubectl apply -f service.yaml || true
- kubectl apply -f ingress.yaml

deploy_live:
image: registry.gitlab.com/gitlab-examples/kubernetes-deploy
stage: deploy
environment:
name: live
url: https://live-presentation-gitlab-k8s.zerbytes.net
name: live/${CI_COMMIT_REF_NAME}
url: https://live-presentation-gitlab-k8s.edenmal.moe
only:
- tags
when: manual
Expand All @@ -102,10 +104,10 @@ deploy_live:
- kubectl config set-credentials default-admin --token=${KUBE_TOKEN}
- kubectl config set-context default-system --cluster=default-cluster --user=default-admin --namespace ${KUBE_NAMESPACE}
- kubectl config use-context default-system
- kubectl cluster-info
- 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 cluster-info
- kubectl get deployments -l app=${CI_ENVIRONMENT_SLUG}
- kubectl apply -f deployment.yaml
- kubectl create -f service.yaml || true
- kubectl apply -f service.yaml || true
- kubectl apply -f ingress.yaml
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM busybox:1.26.2-glibc
FROM busybox:1.28.0-glibc

COPY app /bin/app

Expand Down
75 changes: 75 additions & 0 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

38 changes: 38 additions & 0 deletions Gopkg.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@

# Gopkg.toml example
#
# Refer to https://github.com/golang/dep/blob/master/docs/Gopkg.toml.md
# for detailed Gopkg.toml documentation.
#
# required = ["github.com/user/thing/cmd/thing"]
# ignored = ["github.com/user/project/pkgX", "bitbucket.org/user/project/pkgA/pkgY"]
#
# [[constraint]]
# name = "github.com/user/project"
# version = "1.0.0"
#
# [[constraint]]
# name = "github.com/user/project2"
# branch = "dev"
# source = "github.com/myfork/project2"
#
# [[override]]
# name = "github.com/x/y"
# version = "2.4.0"


[[constraint]]
name = "github.com/Sirupsen/logrus"
version = "1.0.4"

[[constraint]]
name = "github.com/gorilla/handlers"
version = "1.3.0"

[[constraint]]
name = "github.com/prometheus/client_golang"
version = "0.8.0"

[[constraint]]
branch = "master"
name = "github.com/prometheus/common"
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,16 @@ The files are also mainly used in my GitLab post series about the GitLab CI runn
**INFO** This isn't the best way to deploy to K8s, this is a more of an example how simple it can be.

The presentation can be found here: [Kubernetes - WYNTK - GitLab CI + Kubernetes Presentation](https://edenmal.net/2017/07/31/Kubernetes-WYNTK-GitLab-CI-Kubernetes-Presentation/).
The blog post these files were specifically used in is here: [GitLab + Kubernetes: Perfect Match for Continuous Delivery with Container](https://edenmal.net/2017/07/04/GitLab-Kubernetes-Perfect-Match-for-Continuous-Delivery-with-Container/).

The posts around running Kubernetes with and on top of Kubernetes can be found here:
All my blog posts around GitLab and Kubernetes can be found here:
* [GitLab + Kubernetes: Perfect Match for Continuous Delivery with Container](https://edenmal.net/2017/07/04/GitLab-Kubernetes-Perfect-Match-for-Continuous-Delivery-with-Container/)
* [GitLab + Kubernetes: Running CI Runners in Kubernetes](https://edenmal.net/2017/08/31/GitLab-Kubernetes-Running-CI-Runners-in-Kubernetes/)
* [GitLab + Kubernetes: GitLab on top of Kubernetes](https://edenmal.net/2017/11/04/GitLab-Kubernetes-GitLab-on-top-of-Kubernetes/)

## Using these files
You have to replace the following strings in all files:
* `gitlab.edenmal.moe` with your GitLab address (example `gitlab.example.com`)
* `registry.edenmal.moe` with your Docker Registry address (example `registry.example.com`)

Then you can just import the files/repository.
6 changes: 4 additions & 2 deletions deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ metadata:
labels:
app: __CI_ENVIRONMENT_SLUG__
track: stable
annotations:

spec:
replicas: 4
template:
Expand All @@ -14,10 +16,10 @@ spec:
track: stable
spec:
imagePullSecrets:
- name: registry-zerbytes-gitlab-key
- name: registry-edenmal-gitlab-key
containers:
- name: app
image: registry.zerbytes.net/atrost/presentation-gitlab-k8s:__VERSION__
image: registry.edenmal.moe/atrost/presentation-gitlab-k8s:__VERSION__
imagePullPolicy: Always
ports:
- containerPort: 8000
Expand Down
10 changes: 6 additions & 4 deletions ingress.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@ metadata:
kubernetes.io/tls-acme: "true"
kubernetes.io/ingress.class: "nginx"
spec:
tls:
- hosts:
- __CI_ENVIRONMENT_SLUG__-presentation-gitlab-k8s.edenmal.net
secretName: tls-net-edenmal-__CI_ENVIRONMENT_SLUG__-presentation-gitlab-k8s
# When you have a wildcard SSL certificate you can add it here or
# create a self signed certificate on the fly
# tls:
# - hosts:
# - __CI_ENVIRONMENT_SLUG__-presentation-gitlab-k8s.edenmal.net
# secretName: tls-net-edenmal-__CI_ENVIRONMENT_SLUG__-presentation-gitlab-k8s
rules:
- host: __CI_ENVIRONMENT_SLUG__-presentation-gitlab-k8s.edenmal.net
http:
Expand Down
21 changes: 0 additions & 21 deletions manifests/ingress.yaml

This file was deleted.

13 changes: 0 additions & 13 deletions manifests/service.yaml

This file was deleted.

1 change: 1 addition & 0 deletions vendor/github.com/Sirupsen/logrus/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions vendor/github.com/Sirupsen/logrus/.travis.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 24 additions & 0 deletions vendor/github.com/Sirupsen/logrus/CHANGELOG.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit c4d97cb

Please sign in to comment.