-
Notifications
You must be signed in to change notification settings - Fork 0
/
.drone.yml
124 lines (124 loc) · 3.08 KB
/
.drone.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
kind: pipeline
type: docker
name: default
platform:
os: linux
arch: amd64
node:
machine: digitalocean
workspace:
base: /go
path: src/github.com/unknowntpo/todos
steps:
- name: test
image: golang:1.16-alpine
commands:
- apk add --no-cache make build-base
- go install honnef.co/go/tools/cmd/staticcheck@latest
- cp .envrc.example .envrc
- make vendor
- make audit
- name: build
image: golang:1.16-alpine
commands:
#- make build/api
#- chmod +x ./bin/api
- name: push-image
image: docker:20-dind
privileged: true
environment:
DOCKER_USERNAME:
from_secret: docker_username
DOCKER_PASSWORD:
from_secret: docker_password
volumes:
- name: dockersock
path: /var/run
commands:
- apk add --no-cache make git
- sleep 30 # wait for docker daemon finishing setup.
- docker ps -a
- cp .envrc.example .envrc
- make image/build/server
- make image/build/config
# Ref: https://0-8-0.docs.drone.io/manage-secrets/
- docker login --username $${DOCKER_USERNAME} --password $${DOCKER_PASSWORD}
- make image/push/server
- make image/push/config
- name: deploy
image: docker:20-dind
privileged: true
environment:
REMOTE_DOCKER_HOST:
from_secret: remote_docker_host
POSTGRES_USER:
from_secret: postgres_user
POSTGRES_PASSWORD:
from_secret: postgres_password
POSTGRES_DB:
from_secret: postgres_db
TODOS_APP_DB_DSN:
from_secret: todos_app_db_dsn
SSH_KEY:
from_secret: ssh_key
volumes:
- name: dockersock
path: /var/run
commands:
- sleep 20
- apk add --no-cache make git openssh
- docker ps -a
- docker context create production --docker "host=$${REMOTE_DOCKER_HOST}"
- docker context use production
- docker context list
- echo $${REMOTE_DOCKER_HOST}
- echo $${SSH_KEY}
- mkdir -p $HOME/.ssh
- echo "$SSH_KEY" > $HOME/.ssh/id_rsa
- chmod 600 $HOME/.ssh/id_rsa
## TODO: Use docker context deploy
- name: coverage
image: plugins/codecov
settings:
token:
from_secret: codecov_token
files:
- '*.go'
required: true
flags:
- unit
#TODO: Add integration test here.
- name: ssh-deploy
image: appleboy/drone-ssh
settings:
host: todos.unknowntpo.net
username: todos
key:
from_secret: ssh_key
port: 22
timeout: 60s
script_stop: true
script:
- echo $${SSH_KEY}
- whoami
- hostname
- ls -l
- cd deploy
- rm -rf todos
- git clone https://github.com/unknowntpo/todos.git
- cd todos
- cp .envrc.example .envrc
- make production/deploy
# Specify docker:20-dind as a service
# Ref: https://github.com/testcontainers/dind-drone-plugin
services:
- name: docker
image: docker:20-dind
privileged: true
volumes:
- name: dockersock
path: /var/run
detach: true
volumes:
- name: dockersock
temp: {}