Skip to content

Commit afc9314

Browse files
butlerxDanielBrierton
authored andcommitted
Kube/deploy (CoderDojo#149)
* Added staging conf to circle.yml * add k8 deploy * pass build args * Update kube.sh * set args depending on branch * update kube.sh to use uptodate kubctl
1 parent 7d8b2d5 commit afc9314

File tree

3 files changed

+43
-19
lines changed

3 files changed

+43
-19
lines changed

Dockerfile

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
FROM mhart/alpine-node:0.10.48
22
MAINTAINER butlerx <[email protected]>
3-
RUN apk add --update git make gcc g++ python postgresql-client && \
4-
mkdir -p /usr/src/app
3+
ARG DEP_VERSION=latest
4+
RUN apk add --update git build-base python postgresql-client
5+
RUN mkdir -p /usr/src/app
56
WORKDIR /usr/src/app
6-
COPY . /usr/src/app
7-
RUN npm install --production \
8-
&& rm -rf /root/.npm \
9-
&& apk del make gcc g++ python \
10-
&& rm -rf /tmp/* /root/.npm /root/.node-gyp
7+
ADD . /usr/src/app
8+
RUN npm install && \
9+
npm install cp-translations@$DEP_VERSION && \
10+
apk del build-base python && \
11+
rm -rf /tmp/* /root/.npm /root/.node-gyp
1112
EXPOSE 10306
12-
CMD ["npm", "start"]
13+
CMD ["npm", "start"]

circle.yml

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1+
---
12
machine:
23
node:
34
version: 0.10.40
5+
services:
6+
- docker
47
environment:
58
LANG: en_US.utf8
69
dependencies:
@@ -25,14 +28,5 @@ deployment:
2528
deployment_config: CodeDeployDefault.OneAtATime
2629
staging:
2730
branch: staging
28-
codedeploy:
29-
cp-events-service-staging:
30-
application_root: /
31-
region: eu-west-1
32-
revision_location:
33-
revision_type: S3
34-
s3_location:
35-
bucket: zen-deployments
36-
key_pattern: staging/applications/cp-events-service-staging-{SHORT_COMMIT}-{BUILD_NUM}.zip
37-
deployment_group: staging-zen
38-
deployment_config: CodeDeployDefault.OneAtATime
31+
commands:
32+
- GIT_SHA1=$CIRCLE_SHA1 GIT_BRANCH=$CIRCLE_BRANCH ./deploy/kube.sh

deploy/kube.sh

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#!/usr/bin/env bash
2+
3+
set -e
4+
5+
if [ "$GIT_BRANCH" = "master" ]; then
6+
DEP_VER=latest
7+
HOST=$PROD_HOST
8+
echo "$PROD_CA_CERT" | base64 -i --decode > ca.pem
9+
echo "$PROD_ADMIN_KEY" | base64 -i --decode > admin-key.pem
10+
echo "$PROD_ADMIN_CERT" | base64 -i --decode > admin.pem
11+
elif [ "$GIT_BRANCH" = "staging" ]; then
12+
DEP_VER=staging
13+
HOST=$STAGING_HOST
14+
echo "$STAGING_CA_CERT" | base64 -i --decode > ca.pem
15+
echo "$STAGING_ADMIN_KEY" | base64 -i --decode > admin-key.pem
16+
echo "$STAGING_ADMIN_CERT" | base64 -i --decode > admin.pem
17+
else
18+
exit 0
19+
fi
20+
docker build --rm=false --build-arg DEP_VERSION=$DEP_VER -t coderdojo/cp-events-service:"$GIT_SHA1" .
21+
docker login -u "$DOCKER_USER" -p "$DOCKER_PASS" -e "$DOCKER_EMAIL"
22+
docker push coderdojo/cp-events-service:"$GIT_SHA1"
23+
curl -O https://storage.googleapis.com/kubernetes-release/release/v1.6.1/bin/linux/amd64/kubectl
24+
chmod +x kubectl
25+
./kubectl config set-cluster default-cluster --server=https://"$HOST" --certificate-authority=ca.pem
26+
./kubectl config set-credentials default-admin --certificate-authority=ca.pem --client-key=admin-key.pem --client-certificate=admin.pem
27+
./kubectl config set-context default-system --cluster=default-cluster --user=default-admin
28+
./kubectl config use-context default-system
29+
./kubectl patch deployment events -p '{"spec":{"template":{"spec":{"containers":[{"name":"events","image":"coderdojo/cp-events-service:'"$GIT_SHA1"'"}]}}}}'

0 commit comments

Comments
 (0)