diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 00000000..09e11de3 --- /dev/null +++ b/.travis.yml @@ -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 diff --git a/deploy/deploy.sh b/deploy/deploy.sh new file mode 100644 index 00000000..279e1aed --- /dev/null +++ b/deploy/deploy.sh @@ -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 diff --git a/deploy/gcloud-key.json.enc b/deploy/gcloud-key.json.enc new file mode 100644 index 00000000..a14983da Binary files /dev/null and b/deploy/gcloud-key.json.enc differ diff --git a/docker-compose.yml b/docker-compose.yml index d652b6b7..3fe7f8a9 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -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 diff --git a/manifest.yml b/manifest.yml new file mode 100644 index 00000000..b5ca2b6b --- /dev/null +++ b/manifest.yml @@ -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