Backend/.drone.yml

125 lines
3.7 KiB
YAML

---
global-variables:
release: &release ${DRONE_TAG}
environment: &environment
JAVA_VERSION: 11
GRADLE_VERSION: 7.1
CRE_VERSION: dev-${DRONE_BUILD_NUMBER}
CRE_ARTIFACT_NAME: ColorRecipesExplorer
CRE_REGISTRY_IMAGE: registry.fyloz.dev/colorrecipesexplorer/backend
CRE_PORT: 9101
CRE_RELEASE: *release
gradle-image: &gradle-image gradle:7.1-jdk11
alpine-image: &alpine-image alpine:latest
docker-registry: &docker-registry registry.fyloz.dev
docker-registry-repo: &docker-registry-repo registry.fyloz.dev/colorrecipesexplorer/backend
kind: pipeline
name: default
type: docker
steps:
- name: gradle-test
image: *gradle-image
commands:
- gradle test
when:
branch: develop
- name: set-docker-tags-latest
image: *alpine-image
environment:
<<: *environment
commands:
- echo -n "latest" > .tags
when:
branch: develop
event:
exclude:
- pull_request
- name: set-docker-tags-release
image: *alpine-image
environment:
<<: *environment
commands:
- echo -n "latest-release,$CRE_RELEASE" > .tags
when:
event:
- tag
- name: containerize-dev
image: plugins/docker
environment:
<<: *environment
settings:
build_args_from_env:
- GRADLE_VERSION
- JAVA_VERSION
- CRE_VERSION
registry: *docker-registry
repo: *docker-registry-repo
username:
from_secret: docker_username
password:
from_secret: docker_password
when:
branch: develop
event:
exclude:
- pull_request
- name: containerize-release
image: plugins/docker
environment:
<<: *environment
settings:
build_args_from_env:
- GRADLE_VERSION
- JAVA_VERSION
build_args:
- CRE_VERSION=${DRONE_TAG}
registry: *docker-registry
repo: *docker-registry-repo
username:
from_secret: docker_username
password:
from_secret: docker_password
when:
event:
- tag
- name: deploy
image: alpine:latest
environment:
<<: *environment
CRE_REGISTRY_IMAGE: *docker-registry-repo
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
DEPLOY_CONTAINER_NAME: cre_backend
DEPLOY_SPRING_PROFILES: mysql,rest
DEPLOY_DATA_VOLUME: /var/cre/data
DEPLOY_CONFIG_VOLUME: /var/cre/config
DEPLOY_LOGS_VOLUME: /var/cre/logs
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:$CRE_RELEASE"
- 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/data -v $DEPLOY_CONFIG_VOLUME:/usr/bin/config -v $DEPLOY_LOGS_VOLUME:/usr/bin/logs -e spring_profiles_active=$DEPLOY_SPRING_PROFILES $CRE_REGISTRY_IMAGE:$CRE_RELEASE"
when:
event:
- tag