Skip to content

Commit

Permalink
add ci files
Browse files Browse the repository at this point in the history
  • Loading branch information
Administrator committed Feb 3, 2017
1 parent 8666dd9 commit baab4a7
Show file tree
Hide file tree
Showing 7 changed files with 115 additions and 0 deletions.
57 changes: 57 additions & 0 deletions gitlab/ci/.gitlab-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
image: docker:latest

services:
- docker:dind

stages:
- build_test_release
- deploy_staging
- deploy_prod

variables:
CONTAINER_TEST_IMAGE: gregbkr/flask_test
CONTAINER_RELEASE_IMAGE: gregbkr/flask

before_script:
- docker login -u gregbkr -p Geneva2017$

build_test_release:
stage: build_test_release
script:
- docker build --pull -t $CONTAINER_TEST_IMAGE flask/src
- docker push $CONTAINER_TEST_IMAGE
- docker run --name=flask -d -p 5000:5000 $CONTAINER_TEST_IMAGE
- docker run -i --rm --link=flask:flask pstauffer/curl sh < flask/src/test.sh
- docker rm -f -v flask
- docker pull $CONTAINER_TEST_IMAGE
- docker tag $CONTAINER_TEST_IMAGE $CONTAINER_RELEASE_IMAGE
- docker push $CONTAINER_RELEASE_IMAGE

deploy_staging:
stage: deploy_staging
script:
- cd /usr/local/bin
- curl -O https://storage.googleapis.com/kubernetes-release/release/v1.5.1/bin/linux/amd64/kubectl
- chmod +x kubectl
- cd /builds/root/k8-ci
- kubectl config set-cluster kargo --server=https://159.100.252.54:8443 --certificate-authority=kubectl/ca.pem
- kubectl config set-credentials kadmin --certificate-authority=kubectl/ca.pem --client-key=kubectl/admin-node1-key.pem --client-certificate=kubectl/admin-node1.pem
- kubectl config set-context kargo --cluster=kargo --user=kadmin
- kubectl config use-context kargo
- kubectl delete -f flask/flask-deployment.yaml
- kubectl apply -f flask/flask-deployment.yaml

deploy_prod:
stage: deploy_prod
when: manual
script:
- cd /usr/local/bin
- curl -O https://storage.googleapis.com/kubernetes-release/release/v1.5.1/bin/linux/amd64/kubectl
- chmod +x kubectl
- cd /builds/root/k8-ci
- kubectl config set-cluster kargo --server=https://159.100.252.54:8443 --certificate-authority=kubectl/ca.pem
- kubectl config set-credentials kadmin --certificate-authority=kubectl/ca.pem --client-key=kubectl/admin-node1-key.pem --client-certificate=kubectl/admin-node1.pem
- kubectl config set-context kargo --cluster=kargo --user=kadmin
- kubectl config use-context kargo
- kubectl delete -f flask/flask-deployment.yaml
- kubectl apply -f flask/flask-deployment.yaml
17 changes: 17 additions & 0 deletions gitlab/ci/flask/flask-deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: flask
spec:
replicas: 1
template:
metadata:
labels:
app: flask
spec:
containers:
- name: flask
image: gregbkr/flask
imagePullPolicy: Always
ports:
- containerPort: 5000
15 changes: 15 additions & 0 deletions gitlab/ci/flask/flask-service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
apiVersion: v1
kind: Service
metadata:
name: flask
#namespace: default
labels:
app: flask
spec:
type: NodePort
ports:
- port: 5000
nodePort: 30555
selector:
app: flask
6 changes: 6 additions & 0 deletions gitlab/ci/flask/src/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
FROM python:2.7
ADD . /code
WORKDIR /code
RUN pip install -r requirements.txt
ENTRYPOINT ["python"]
CMD ["app.py"]
10 changes: 10 additions & 0 deletions gitlab/ci/flask/src/app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from flask import Flask

app = Flask(__name__)

@app.route("/")
def hello_world():
return "Hello World 1!"

if __name__ == "__main__":
app.run(debug=True,host='0.0.0.0')
2 changes: 2 additions & 0 deletions gitlab/ci/flask/src/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
flask
redis
8 changes: 8 additions & 0 deletions gitlab/ci/flask/src/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
sleep 5
if curl flask:5000 | grep 'Hello World'; then
echo "Tests passed!"
exit 0
else
echo "Tests failed!"
exit 1
fi

0 comments on commit baab4a7

Please sign in to comment.