-
Notifications
You must be signed in to change notification settings - Fork 126
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes #300 Kubernetes config added for autodeployment
- Loading branch information
1 parent
61d27d1
commit ccdc956
Showing
20 changed files
with
340 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#!/bin/bash | ||
export DIR=${BASH_SOURCE%/*} | ||
|
||
if [ "$1" = "delete" ]; then | ||
echo "Clearing the cluster." | ||
if [ "$2" = "all" ]; then | ||
kubectl delete -f ${DIR}/yamls/nginx/00-namespace.yml | ||
fi | ||
kubectl delete -f ${DIR}/yamls/web/00-namespace.yml | ||
echo "Done. The project was removed from the cluster." | ||
elif [ "$1" = "create" ]; then | ||
echo "Deploying the project to kubernetes cluster" | ||
if [ "$2" = "all" ]; then | ||
# Start nginx deployment, ingress & service | ||
kubectl create -R -f ${DIR}/yamls/nginx | ||
fi | ||
# Create web namespace | ||
kubectl create -R -f ${DIR}/yamls/web | ||
# Create API server deployment and service | ||
kubectl create -R -f ${DIR}/yamls/yaydoc | ||
echo "Waiting for server to start up. ~30s." | ||
sleep 30 | ||
echo "Done. The project was deployed to kubernetes. :)" | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
FROM node:boron | ||
MAINTAINER Ujjwal Bhardwaj <[email protected]> | ||
|
||
ARG COMMIT_HASH | ||
ARG BRANCH | ||
ARG REPOSITORY | ||
|
||
ENV COMMIT_HASH ${COMMIT_HASH:-null} | ||
ENV BRANCH ${BRANCH:-master} | ||
ENV REPOSITORY ${REPOSITORY:-https://github.com/fossasia/yaydoc.git} | ||
|
||
ENV INSTALL_PATH /yaydoc | ||
|
||
RUN mkdir -p $INSTALL_PATH | ||
|
||
WORKDIR $INSTALL_PATH | ||
|
||
COPY . . | ||
|
||
RUN apt-get update && \ | ||
apt-get install -y python python-dev python-pip python-virtualenv zip rsync default-jdk && \ | ||
rm -rf /var/lib/apt/lists/* | ||
|
||
ENV JAVA_HOME /usr/lib/jvm/default-java/ | ||
RUN export JAVA_HOME | ||
|
||
RUN bash setup.sh | ||
|
||
WORKDIR $INSTALL_PATH/yaydoc | ||
|
||
CMD [ "npm", "start" ] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#!/bin/bash | ||
git clone ${REPOSITORY} yaydoc | ||
cd yaydoc | ||
git checkout ${BRANCH} | ||
|
||
if [ -v COMMIT_HASH ]; then | ||
git reset --hard ${COMMIT_HASH} | ||
fi | ||
|
||
npm install --no-shrinkwrap | ||
|
||
pip install -r requirements.txt | ||
|
||
wget -qO- https://cli-assets.heroku.com/install-ubuntu.sh | sh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
#!/usr/bin/env bash | ||
|
||
export DEPLOY_BRANCH=${DEPLOY_BRANCH:-master} | ||
|
||
if [ "$TRAVIS_PULL_REQUEST" != "false" -o "$TRAVIS_REPO_SLUG" != "fossasia/yaydoc" -o "$TRAVIS_BRANCH" != "$DEPLOY_BRANCH" ]; then | ||
echo "Skip production deployment for a very good reason." | ||
exit 0 | ||
fi | ||
|
||
export REPOSITORY="https://github.com/${TRAVIS_REPO_SLUG}.git" | ||
|
||
sudo rm -f /usr/bin/git-credential-gcloud.sh | ||
sudo rm -f /usr/bin/bq | ||
sudo rm -f /usr/bin/gsutil | ||
sudo rm -f /usr/bin/gcloud | ||
rm -rf node_modules | ||
|
||
curl https://sdk.cloud.google.com | bash; | ||
source ~/.bashrc | ||
gcloud components install kubectl | ||
|
||
gcloud config set compute/zone us-central1-c | ||
# Decrypt the credentials we added to the repo using the key we added with the Travis command line tool | ||
openssl aes-256-cbc -K $encrypted_512fe31a4705_key -iv $encrypted_512fe31a4705_iv -in ./kubernetes/travis/yaydoc-ujjwal-7b7e19a433b1.json.enc -out yaydoc-ujjwal-7b7e19a433b1.json -d | ||
gcloud auth activate-service-account --key-file yaydoc-ujjwal-7b7e19a433b1.json | ||
export GOOGLE_APPLICATION_CREDENTIALS=$(pwd)/yaydoc-ujjwal-7b7e19a433b1.json | ||
|
||
gcloud config set project yaydoc-ujjwal | ||
gcloud container clusters get-credentials sample | ||
cd kubernetes/images/yaydoc | ||
docker build --build-arg COMMIT_HASH=$TRAVIS_COMMIT --build-arg BRANCH=$DEPLOY_BRANCH --build-arg REPOSITORY=$REPOSITORY --no-cache -t ujjwalbhardwaj/yaydoc:$TRAVIS_COMMIT . | ||
docker login -u="$DOCKER_USERNAME" -p="$DOCKER_PASSWORD" | ||
docker tag ujjwalbhardwaj/yaydoc:$TRAVIS_COMMIT ujjwalbhardwaj/yaydoc:latest | ||
docker push ujjwalbhardwaj/yaydoc | ||
kubectl set image deployment/yay --namespace=default yay=ujjwalbhardwaj/yaydoc:$TRAVIS_COMMIT | ||
rm -rf $GOOGLE_APPLICATION_CREDENTIALS |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
apiVersion: v1 | ||
kind: Namespace | ||
metadata: | ||
name: nginx-ingress |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# | ||
# nginx ingress controller config | ||
# @ref https://github.com/kubernetes/ingress/blob/master/controllers/nginx/configuration.md | ||
# | ||
apiVersion: v1 | ||
data: | ||
proxy-connect-timeout: "15" | ||
proxy-read-timeout: "600" | ||
proxy-send-imeout: "600" | ||
hsts-include-subdomains: "false" | ||
body-size: "64m" | ||
server-name-hash-bucket-size: "256" | ||
server-tokens: "false" | ||
kind: ConfigMap | ||
metadata: | ||
namespace: nginx-ingress | ||
name: nginx |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
apiVersion: apps/v1beta1 | ||
kind: Deployment | ||
metadata: | ||
name: default-http-backend | ||
namespace: nginx-ingress | ||
spec: | ||
replicas: 1 | ||
template: | ||
metadata: | ||
labels: | ||
app: default-http-backend | ||
spec: | ||
containers: | ||
- name: default-http-backend | ||
image: gcr.io/google_containers/defaultbackend:1.0 | ||
livenessProbe: | ||
httpGet: | ||
path: /healthz | ||
port: 8080 | ||
scheme: HTTP | ||
initialDelaySeconds: 30 | ||
timeoutSeconds: 5 | ||
ports: | ||
- containerPort: 8080 | ||
resources: | ||
limits: | ||
cpu: 10m | ||
memory: 20Mi | ||
requests: | ||
cpu: 10m | ||
memory: 20Mi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
apiVersion: v1 | ||
kind: Service | ||
metadata: | ||
name: default-http-backend | ||
namespace: nginx-ingress | ||
spec: | ||
ports: | ||
- port: 80 | ||
targetPort: 8080 | ||
protocol: TCP | ||
selector: | ||
app: default-http-backend |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
apiVersion: apps/v1beta1 | ||
kind: Deployment | ||
metadata: | ||
name: nginx | ||
namespace: nginx-ingress | ||
spec: | ||
replicas: 1 | ||
template: | ||
metadata: | ||
labels: | ||
app: nginx | ||
spec: | ||
containers: | ||
- image: gcr.io/google_containers/nginx-ingress-controller:0.8.3 | ||
name: nginx | ||
imagePullPolicy: Always | ||
env: | ||
- name: POD_NAME | ||
valueFrom: | ||
fieldRef: | ||
fieldPath: metadata.name | ||
- name: POD_NAMESPACE | ||
valueFrom: | ||
fieldRef: | ||
fieldPath: metadata.namespace | ||
livenessProbe: | ||
httpGet: | ||
path: /healthz | ||
port: 10254 | ||
scheme: HTTP | ||
initialDelaySeconds: 30 | ||
timeoutSeconds: 5 | ||
ports: | ||
- containerPort: 80 | ||
- containerPort: 443 | ||
args: | ||
- /nginx-ingress-controller | ||
- --default-backend-service=nginx-ingress/default-http-backend | ||
- --nginx-configmap=nginx-ingress/nginx |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
apiVersion: v1 | ||
kind: Service | ||
metadata: | ||
name: nginx | ||
namespace: nginx-ingress | ||
annotations: | ||
service.beta.kubernetes.io/external-traffic: "OnlyLocal" | ||
spec: | ||
type: LoadBalancer | ||
loadBalancerIP: '35.197.18.246' | ||
ports: | ||
- port: 80 | ||
name: http | ||
- port: 443 | ||
name: https | ||
selector: | ||
app: nginx |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
apiVersion: v1 | ||
kind: Namespace | ||
metadata: | ||
name: web |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
apiVersion: extensions/v1beta1 | ||
kind: Ingress | ||
metadata: | ||
name: yaydoc-notls | ||
namespace: web | ||
annotations: | ||
kubernetes.io/ingress.class: "nginx" | ||
spec: | ||
rules: | ||
- host: yaydoc.tk | ||
http: | ||
paths: | ||
- path: / | ||
backend: | ||
serviceName: yaydoc | ||
servicePort: 3001 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
apiVersion: extensions/v1beta1 | ||
kind: Ingress | ||
metadata: | ||
name: yaydoc | ||
namespace: web | ||
annotations: | ||
kubernetes.io/tls-acme: "true" | ||
kubernetes.io/ingress.class: "nginx" | ||
spec: | ||
tls: | ||
- hosts: | ||
- yaydoc.tk | ||
secretName: yaydoc-tls | ||
rules: | ||
- host: yaydoc.tk | ||
http: | ||
paths: | ||
- path: / | ||
backend: | ||
serviceName: yaydoc | ||
servicePort: 3001 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
apiVersion: v1 | ||
metadata: | ||
name: yaydoc | ||
namespace: web | ||
data: | ||
DEPLOYMENT: "true" | ||
ENCRYPTION_KEY: "xxxxxxxxxxxxxxxxxxxxxxx" | ||
GITHUB_CLIENT_ID: "xxxxxxxxxxxxxxxxxxxxxxx" | ||
GITHUB_CLIENT_SECRET: "xxxxxxxxxxxxxxxxxxxxxxx" | ||
GITHUB_CALLBACK_URL: "xxxxxxxxxxxxxxxxxxxxxxx" | ||
HEROKU_CLIENT_ID: "xxxxxxxxxxxxxxxxxxxxxxx" | ||
HEROKU_CLIENT_SECRET: "xxxxxxxxxxxxxxxxxxxxxxx" | ||
HEROKU_CALLBACK_URL: "xxxxxxxxxxxxxxxxxxxxxxx" | ||
HOSTNAME: "xxxxxxxxxxxx" | ||
MONGODB_URI: "xxxxxxxxxxxxxxxxxxxxxxxxx" | ||
SECRET: "xxxxxxxxxxxxxxx" | ||
SENDGRID_USERNAME: "xxxxxxxxx" | ||
SENDGRID_PASSWORD: "xxxxxxxxx" | ||
kind: ConfigMap |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
kind: Deployment | ||
apiVersion: apps/v1beta1 | ||
metadata: | ||
name: yaydoc | ||
namespace: web | ||
spec: | ||
replicas: 1 | ||
template: | ||
metadata: | ||
labels: | ||
app: yaydoc | ||
spec: | ||
containers: | ||
- name: yaydoc | ||
image: ujjwalbhardwaj/yaydoc:latest | ||
livenessProbe: | ||
httpGet: | ||
path: / | ||
port: 3001 | ||
initialDelaySeconds: 15 | ||
timeoutSeconds: 1 | ||
ports: | ||
- containerPort: 3001 | ||
protocol: TCP | ||
envFrom: | ||
- configMapRef: | ||
name: yaydoc | ||
restartPolicy: Always |
Oops, something went wrong.