Backend/.drone.yml

73 lines
2.4 KiB
YAML
Raw Normal View History

2021-07-31 19:13:20 -04:00
kind: pipeline
name: default
2021-08-01 00:28:40 -04:00
type: docker
environment:
2021-08-01 16:23:29 -04:00
CRE_VERSION: ${DRONE_BUILD_NUMBER}
2021-08-01 16:34:38 -04:00
CRE_ARTIFACT_NAME: ColorRecipesExplorer
2021-08-01 00:28:40 -04:00
CRE_REGISTRY_IMAGE: registry.fyloz.dev:5443/colorrecipesexplorer/backend
CRE_PORT: 9101
2021-07-31 19:13:20 -04:00
steps:
2021-08-01 17:27:16 -04:00
- name: test
image: gradle:7.1-jdk11
commands:
- gradle test
2021-08-01 00:28:40 -04:00
- name: build
2021-08-01 11:45:26 -04:00
image: gradle:7.1-jdk11
2021-08-01 00:28:40 -04:00
commands:
2021-08-01 16:23:29 -04:00
- gradle bootJar -Pversion=$CRE_VERSION
2021-08-01 16:49:11 -04:00
- mv build/libs/ColorRecipesExplorer-$CRE_VERSION.jar $CRE_ARTIFACT_NAME.jar
2021-08-01 17:21:11 -04:00
- echo -n "latest,$CRE_VERSION" > .tags
2021-08-01 00:28:40 -04:00
when:
branch:
- master
2021-08-01 17:27:16 -04:00
events: [ push, tag ]
2021-08-01 00:28:40 -04:00
- name: containerize
image: plugins/docker
settings:
2021-08-01 17:21:11 -04:00
build_args:
- JAVA_VERSION=11
2021-08-01 17:05:59 -04:00
repo: registry.fyloz.dev:5443/colorrecipesexplorer/backend
2021-08-01 00:28:40 -04:00
when:
branch:
- master
2021-08-01 17:27:16 -04:00
events: [ push, tag ]
2021-08-01 00:28:40 -04:00
- name: deploy
image: alpine:latest
environment:
DEPLOY_SERVER:
from_secret: deploy_server
DEPLOY_SERVER_USERNAME:
from_secret: deploy_server_username
DEPLOY_SERVER_SSH_PORT:
from_secret: deploy_server_ssh_port
DEPLOY_SERVER_SSH_KEY:
from_secret: deploy_server_ssh_key
2021-08-01 16:23:29 -04:00
DEPLOY_CONTAINER_NAME: cre_backend-${DRONE_BRANCH}
2021-08-01 00:28:40 -04:00
DEPLOY_SPRING_PROFILES: mysql,rest
DEPLOY_DATA_VOLUME: /var/cre/data
DEPLOY_CONFIG_VOLUME: /var/cre/config
commands:
- apk update
- apk add --no-cache openssh-client
- mkdir -p ~/.ssh
- echo "$DEPLOY_SERVER_SSH_KEY" | tr -d '\r' > ~/.ssh/id_rsa
- chmod 700 ~/.ssh/id_rsa
- eval $(ssh-agent -s)
- ssh-add ~/.ssh/id_rsa
- ssh-keyscan -p $DEPLOY_SERVER_SSH_PORT -H $DEPLOY_SERVER >> ~/.ssh/known_hosts
- '[[ -f /.dockerenv ]] && echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config'
- ssh -p $DEPLOY_SERVER_SSH_PORT $DEPLOY_SERVER_USERNAME@$DEPLOY_SERVER "docker stop $DEPLOY_CONTAINER_NAME || true && docker rm $DEPLOY_CONTAINER_NAME || true"
- ssh -p $DEPLOY_SERVER_SSH_PORT $DEPLOY_SERVER_USERNAME@$DEPLOY_SERVER "docker pull $CRE_REGISTRY_IMAGE:latest"
2021-08-01 21:55:51 -04:00
- ssh -p $DEPLOY_SERVER_SSH_PORT $DEPLOY_SERVER_USERNAME@$DEPLOY_SERVER "docker run -d -p $CRE_PORT:9090 --name=$DEPLOY_CONTAINER_NAME -v $DEPLOY_DATA_VOLUME:/usr/bin/cre/data -v $DEPLOY_CONFIG_VOLUME:/usr/bin/cre/config -e spring_profiles_active=$DEPLOY_SPRING_PROFILES $CRE_REGISTRY_IMAGE"
2021-08-01 00:28:40 -04:00
when:
branch:
- master
2021-08-01 17:27:16 -04:00
events: [ push, tag ]
2021-08-01 00:28:40 -04:00