Created
October 6, 2016 17:02
-
-
Save wbuchwalter/33cb9ab1d099ed4c00d771d400d2c1b2 to your computer and use it in GitHub Desktop.
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
image: docker:git | |
services: | |
- docker:dind | |
variables: | |
IMAGE_NAME: "something/app" | |
IMAGE_URL: "something/repo" | |
before_script: | |
# install ssh-agent | |
- 'which ssh-agent || ( apt-get update -y && apt-get install openssh-client -y )' | |
# run ssh-agent | |
- eval $(ssh-agent -s) | |
#copy key to file | |
- echo "$SSH_PRIVATE_KEY" > ./key.file | |
- chmod 400 ./key.file | |
# add ssh key stored in SSH_PRIVATE_KEY variable to the agent store | |
- ssh-add ./key.file | |
# disable host key checking (NOTE: makes you susceptible to man-in-the-middle attacks) | |
# WARNING: use only in docker container, if you use it with shell you will overwrite your user's ssh config | |
- mkdir -p ~/.ssh | |
- '[[ -f /.dockerenv ]] && echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config' | |
stages: | |
- build | |
- deploy | |
build_image_job: | |
stage: build | |
script: | |
- docker build -t $IMAGE_NAME . | |
- docker tag $IMAGE_NAME $IMAGE_URL:$CI_BUILD_REF | |
- docker run -dP --name="app" $IMAGE_NAME | |
- sleep 10 | |
- docker exec app npm run unit | |
- docker exec app npm run integration | |
- docker login -u user -p passw0rd | |
- docker push $IMAGE_URL | |
deploy_image_job: | |
stage: deploy | |
environment: production | |
only: | |
- master | |
script: | |
- ssh [email protected] "docker service update app --image $IMAGE_URL:$CI_BUILD_REF" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment