Skip to content

Commit

Permalink
feat(#9): configure ci/cd pipeline
Browse files Browse the repository at this point in the history
  • Loading branch information
matheusbsilva committed Jun 11, 2019
1 parent d794134 commit 63cb04c
Show file tree
Hide file tree
Showing 5 changed files with 91 additions and 1 deletion.
33 changes: 33 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
sudo: required
services:
- docker
cache:
directories:
- "$HOME/google-cloud-sdk/"
env:
global:
- GOOGLE_APPLICATION_CREDENTIALS=$TRAVIS_BUILD_DIR/deploy/gcloud-key.json
- ORG_NAME=estudeplus
- IMAGE_NAME=interface
- DEPLOYMENT=interface-deploy
- CONTAINER=interface-container
- CLOUDSDK_CORE_DISABLE_PROMPTS=1
- secure: fT7UXGY7ouBYlQismnu97CRzZt775MuARvSaUn90iHoaK5G65EFLdU4dPz4x6mthCoaPGIT0tTbfLpbV+3YIBbiTqe+Ice0JCL4RditqqCKv867+T4d6HETvz+R/0qLKQ9vGAgziwqh/GynojNRM4p38INEnixBBGYSYgD2rVot397dxF9tgctof5w7b2y0EoJKhyYyyUNAz6KuJjp7LOAJz3StGtycHiTMXsiZk+uaFhnkU+JN8Pzk1fYbeN0s5mhk6CJfTchk6ytAjKt1BQAn65sA92KUq2CTx+rzngnTK7oYXUV2B3YTVDXgbLoSAPD5gPyM3OKF4+uxGEsomrlB50MflXp0dyC1WhlbLdki7I88yY/cGg4BD+Ay/eBfVtWYt1wNOhFkp9sEwuN2EAk28PXv8bk+ATM0qNSXhV2FleN5K1Q50eyRRM94BgavGXFYAwuBI8iS/JNPdSJzf1w+iARNZLv0oZskmVxuLE/T7zj9a+XIXfPKS8j5fInY9RNoZ+194lAoSfDTD8deaUiXfITcj4l7ChaG9KDSVnKm1aVZpCDVFrs7Dh6UpP43jNVKyVqNh5pFoOAR62AkJGSDZhoyj1LCY0JTRkjZJ2gOuhwuOrjNGbdKg/nKHD60n0CgU/8RTOuy7rckUVdjvQRiGX1Ms4zB7BmfXkha0Yfs=
script:
- docker build -t ${ORG_NAME}/${IMAGE_NAME}:$TRAVIS_COMMIT .
before_deploy:
- if [ ! -d "$HOME/google-cloud-sdk/bin" ]; then rm -rf $HOME/google-cloud-sdk; curl
https://sdk.cloud.google.com | bash > /dev/null; fi
- source $HOME/google-cloud-sdk/path.bash.inc
- gcloud --quiet components update kubectl
deploy:
- provider: script
script: chmod +x deploy/deploy.sh && bash deploy/deploy.sh
skip_cleanup: true
on:
branch: feat#9/deploy-cicd
notifications:
email: false
before_install:
- openssl aes-256-cbc -K $encrypted_616071dd0d17_key -iv $encrypted_616071dd0d17_iv
-in $TRAVIS_BUILD_DIR/deploy/gcloud-key.json.enc -out $TRAVIS_BUILD_DIR/deploy/gcloud-key.json -d
22 changes: 22 additions & 0 deletions deploy/deploy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@

#!/bin/bash

echo "Setting up GCLOUD auth"
gcloud auth activate-service-account --key-file ${TRAVIS_BUILD_DIR}/deploy/gcloud-key.json

gcloud --quiet config set project $PROJECT_ID
gcloud --quiet config set container/cluster $CLUSTER
gcloud --quiet config set compute/zone $ZONE

echo "Getting cluster credentials"
gcloud --quiet container clusters get-credentials $CLUSTER

echo "Authenticating on DockerHub"
echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin


echo "Pushing new image"
docker push ${ORG_NAME}/${IMAGE_NAME}:$TRAVIS_COMMIT

echo "Setting new image on deployment"
kubectl set image deployment/${DEPLOYMENT} ${CONTAINER}=${ORG_NAME}/${IMAGE_NAME}:$TRAVIS_COMMIT
Binary file added deploy/gcloud-key.json.enc
Binary file not shown.
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ services:
volumes:
# Da pasta local (.) para a pasta /usr/src/app dentro do container
- .:/usr/src/app
- /usr/src/app/to/node_modules
- /usr/src/app/node_modules
# Referências: https://docs.docker.com/compose/compose-file/
# Para executar rode:
# (sudo) docker-compose up
35 changes: 35 additions & 0 deletions manifest.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
apiVersion: v1
kind: Service
metadata:
name: interface-service
spec:
type: LoadBalancer
ports:
- port: 80
targetPort: 3000
selector:
app: interface
---
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: interface-deploy
spec:
replicas: 1
template:
metadata:
labels:
app: interface
spec:
containers:
- image: estudeplus/interface
imagePullPolicy: Always
livenessProbe:
failureThreshold: 5
httpGet:
path: /
port: 3000
scheme: HTTP
name: interface-container
ports:
- containerPort: 3000

0 comments on commit 63cb04c

Please sign in to comment.