butler/build/ci/.drone.yml

79 lines
1.9 KiB
YAML

kind: pipeline
type: docker
name: default
steps:
- name: test
pull: if-not-exists
image: golang:1.20
commands:
- go test ./...
- name: build
pull: if-not-exists
image: golang:1.20
environment:
TELEGRAM_TOKEN:
from_secret: TELEGRAM_TOKEN
POSTGRES_URL_CONNECT:
from_secret: POSTGRES_URL_CONNECT
settings:
envs: [ TELEGRAM_TOKEN,POSTGRES_URL_CONNECT ]
commands:
- CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o butler cmd/butler/main.go
- touch .env
- echo TELEGRAM_TOKEN=$${TELEGRAM_TOKEN} >> .env
- echo POSTGRES_URL_CONNECT=$${POSTGRES_URL_CONNECT} >> .env
- name: copy to server
pull: if-not-exists
image: appleboy/drone-scp
settings:
host:
from_secret: SSH_IP
username:
from_secret: SSH_USER
key:
from_secret: SSH_KEY
port:
from_secret: SSH_PORT
target: /home/crab/deploys/butler_bot
source:
- .env
- build/ci/Dockerfile
- deploy/docker-compose.yml
- migrations
- butler
rm: true
- name: deploy
pull: if-not-exists
image: appleboy/drone-ssh
environment:
DB_PASS:
from_secret: DB_PASS
settings:
host:
from_secret: SSH_IP
username:
from_secret: SSH_USER
key:
from_secret: SSH_KEY
port:
from_secret: SSH_PORT
envs: [ DB_PASS ]
script:
- cd /home/crab/deploys/butler_bot
- cp /etc/ssl/certs/ca-certificates.crt .
- mv build/ci/Dockerfile .
- mv deploy/docker-compose.yml .
- rm -r build deploy
- export PATH=$PATH:/usr/local/go/bin:/$HOME/go/bin
- goose -allow-missing -dir ./migrations postgres \"user=crab password=$${DB_PASS} dbname=butler host=localhost port=5432 sslmode=disable\" up >> migrate.sh
- docker-compose up -d --force-recreate
trigger:
event:
- push