Skip to content

Instantly share code, notes, and snippets.

@andarilhoz
Created June 13, 2018 19:06
Show Gist options
  • Save andarilhoz/ec325dee510c2cffa2a5af2e9bbcc8b6 to your computer and use it in GitHub Desktop.
Save andarilhoz/ec325dee510c2cffa2a5af2e9bbcc8b6 to your computer and use it in GitHub Desktop.
cache:
key: "$CI_BUILD_REF_NAME node:8-alpine"
paths:
- node_modules/
stages:
- build
- release
- deploy
build:
stage: build
image: node:8-alpine
variables:
NODE_ENV: "development"
before_script:
- apk add --update bash python make g++
- apk add --update git && rm -rf /tmp/* /var/cache/apk/*
script:
- npm install
artifacts:
paths:
- server/
- public/
release:
stage: release
image: docker:latest
only:
- "master"
services:
- docker:dind
variables:
DOCKER_DRIVER: "overlay"
before_script:
- docker version
- "docker info"
- "docker login -u ${DEPLOYMENT_SERVER_USER} -p ${DEPLOYMENT_SERVER_PASSWORD} ${DEPLOYMENT_SERVER_ADDRESS}"
script:
- "docker build -t ${DEPLOYMENT_SERVER_ADDRESS}/${CI_PROJECT_PATH}:latest --pull ."
- "docker push ${DEPLOYMENT_SERVER_ADDRESS}/${CI_PROJECT_PATH}:latest"
after_script:
- "docker logout ${DEPLOYMENT_SERVER_ADDRESS}"
deploy:
stage: deploy
image: gitlab/dind:latest
only:
- "master"
environment: production
services:
- docker:dind
before_script:
- mkdir -p ~/.ssh
- echo "$DEPLOY_SERVER_PRIVATE_KEY" | tr -d '\r' > ~/.ssh/id_rsa
- chmod 600 ~/.ssh/id_rsa
- eval "$(ssh-agent -s)"
- ssh-add ~/.ssh/id_rsa
- ssh-keyscan -H $DEPLOYMENT_SERVER_IP >> ~/.ssh/known_hosts
script:
- ssh root@$DEPLOYMENT_SERVER_IP "docker login -u ${DEPLOYMENT_SERVER_USER} -p ${DEPLOYMENT_SERVER_PASSWORD} ${DEPLOYMENT_SERVER_ADDRESS}; docker-compose -f ${DEPLOYMENT_COMPOSE_PATH} stop; docker-compose -f ${DEPLOYMENT_COMPOSE_PATH} rm ${COMPOSE_DOCKER_NAME} --force; docker pull ${DEPLOYMENT_SERVER_ADDRESS}/${CI_PROJECT_PATH}:latest; docker-compose -f ${DEPLOYMENT_COMPOSE_PATH} up -d"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment