Skip to content

Instantly share code, notes, and snippets.

@tadite
Created November 2, 2021 16:24
Show Gist options
  • Save tadite/ba4dfb993b0dac3b87e36ac7b89cc978 to your computer and use it in GitHub Desktop.
Save tadite/ba4dfb993b0dac3b87e36ac7b89cc978 to your computer and use it in GitHub Desktop.
variables:
MAVEN_CLI_OPTS: "-s ./settings.xml --batch-mode"
MAVEN_OPTS: "-Dmaven.repo.local=.m2/repository -Dhttps.protocols=TLSv1.2"
cache:
paths:
- .m2/repository/
build:
image: maven:latest
stage: build
script:
- mvn $MAVEN_CLI_OPTS test package
artifacts:
paths:
- ./target/*.jar
docker-build:
stage: deploy
image: docker:latest
services:
- docker:dind
variables:
DOCKER_DRIVER: overlay2
DOCKER_TLS_CERTDIR: ""
script:
- docker build -t $DOCKER_REPO_IMAGE .
- echo $DOCKER_REPO_PASS|docker login --username $DOCKER_REPO_USER --password-stdin $DOCKER_REPO_ADDRESS
- docker push $DOCKER_REPO_IMAGE
artifacts:
paths:
- ./target/*.jar
only:
- develop
docker-compose-deploy:
stage: deploy
image: ubuntu:latest
before_script:
- which ssh-agent || ( apt-get update -y && apt-get install openssh-client -y )
- eval $(ssh-agent -s)
- echo "$SSH_PRIVATE_KEY" | tr -d '\r' | ssh-add -
- mkdir -p ~/.ssh
- chmod 700 ~/.ssh
- ssh-keyscan $SSH_HOST >> ~/.ssh/known_hosts
- chmod 644 ~/.ssh/known_hosts
- ssh-copy-id $SSH_HOST
script:
- ssh $SSH_USER@$SSH_HOST "sudo docker-compose pull $SERVICE_NAME && sudo docker-compose up -d --no-deps --force-recreate $SERVICE_NAME && exit"
only:
- develop
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment