From 819feb6401acac3339ceb8d4c68e3071273c75c8 Mon Sep 17 00:00:00 2001 From: Joakim Olsson Date: Mon, 11 Feb 2019 12:52:32 +0100 Subject: [PATCH] Add build pipeline and deployment files --- .dockerignore | 4 ++++ .gitlab-ci.yml | 27 ++++++++++++++++++++++ Dockerfile | 11 +++++++++ deployment_files/deploy.yaml | 45 ++++++++++++++++++++++++++++++++++++ 4 files changed, 87 insertions(+) create mode 100644 .dockerignore create mode 100644 .gitlab-ci.yml create mode 100644 Dockerfile create mode 100644 deployment_files/deploy.yaml diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..ac0b26d --- /dev/null +++ b/.dockerignore @@ -0,0 +1,4 @@ +vendor +.gitignore +.git +Dockerfile diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml new file mode 100644 index 0000000..3d6cdf2 --- /dev/null +++ b/.gitlab-ci.yml @@ -0,0 +1,27 @@ +stages: + - build + - deploy + +variables: + DOCKER_HOST: tcp://docker:2375/ + +image: registry.gitlab.com/sparetimecoders/build-tools + +build: + stage: build + services: + - docker:dind + script: + - build + - push + +deploy: + stage: deploy + when: on_success + script: + - echo Deploying + - deploy prod + environment: + name: prod + only: + - master diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..73dec98 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,11 @@ +FROM gunosy/ci-go-glide as builder +WORKDIR /go/src/gitlab.com/unboundsoftware/geo-service +COPY glide.* ./ +RUN glide install +COPY * ./ +RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o geo-service . + +FROM scratch +COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ +COPY --from=builder /go/src/gitlab.com/unboundsoftware/geo-service/geo-service / +CMD ["/geo-service"] diff --git a/deployment_files/deploy.yaml b/deployment_files/deploy.yaml new file mode 100644 index 0000000..37f02a6 --- /dev/null +++ b/deployment_files/deploy.yaml @@ -0,0 +1,45 @@ +apiVersion: extensions/v1beta1 +kind: Deployment +metadata: + labels: + app: geo-service + name: geo-service + annotations: + kubernetes.io/change-cause: "${TIMESTAMP} Deployed commit id: ${COMMIT}" +spec: + replicas: 1 + selector: + matchLabels: + app: geo-service + strategy: + rollingUpdate: + maxSurge: 1 + maxUnavailable: 1 + type: RollingUpdate + template: + metadata: + labels: + app: geo-service + spec: + affinity: + podAntiAffinity: + preferredDuringSchedulingIgnoredDuringExecution: + - weight: 100 + podAffinityTerm: + labelSelector: + matchExpressions: + - key: "app" + operator: In + values: + - geo-service + topologyKey: kubernetes.io/hostname + containers: + - name: geo-service + resources: + limits: + memory: "100Mi" + requests: + memory: "100Mi" + imagePullPolicy: Always + image: registry.gitlab.com/unboundsoftware/dancefinder/geo-service:${COMMIT} + restartPolicy: Always