-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbitbucket-pipelines.yml
137 lines (131 loc) · 4.38 KB
/
bitbucket-pipelines.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
125
126
127
128
129
130
131
132
133
134
135
136
137
# Template python-build
# This template allows you to validate your python code.
# The workflow allows running tests and code linting on the default branch.
image: antalvarenga/python-poetry:latest
pipelines:
pull-requests:
'**':
- step:
name: Install dependencies
caches:
- venv
artifacts:
- .venv/**
script:
- poetry install
- parallel:
- step:
name: Test
script:
- poetry run pytest -v --cov
services:
- postgres
- step:
name: Lint
caches:
- pre-commit
script:
- poetry run pre-commit install --install-hooks
- poetry run pre-commit run --all-files
branches:
master:
- step:
name: Build & push app
trigger: manual #this errors on purpose so that pipeline doesn't run
script:
- docker build -t antalvarenga/poetry-flask .
- echo DOCKERHUB_USERNAME=${DOCKERHUB_USERNAME}
- echo DOCKERHUB_PASSWORD=${DOCKERHUB_PASSWORD}
- echo ${DOCKERHUB_PASSWORD} | docker login --username "$DOCKERHUB_USERNAME" --password-stdin
- docker push antalvarenga/poetry-flask:latest
services:
- docker
caches:
- docker
condition:
changesets:
includePaths:
- "app/**"
- "poetry.lock"
- "pyproject.toml"
- "Dockerfile"
- "bitbucket-pipelines.yml"
- step:
name: Build & push nginx
trigger: manual
script:
- docker build -f nginx.Dockerfile -t antalvarenga/nginx .
- echo DOCKERHUB_USERNAME=${DOCKERHUB_USERNAME}
- echo DOCKERHUB_PASSWORD=${DOCKERHUB_PASSWORD}
- echo ${DOCKERHUB_PASSWORD} | docker login --username "$DOCKERHUB_USERNAME" --password-stdin
- docker push antalvarenga/nginx:latest
services:
- docker
caches:
- docker
condition:
changesets:
includePaths:
- "nginx.Dockerfile"
- "nginx/nginx_default.conf"
- "bitbucket-pipelines.yml"
- step:
name: Copy docker-compose file to remote
trigger: manual
script:
- pipe: atlassian/scp-deploy:1.2.1
variables:
USER: 'root'
SERVER: '46.101.106.188'
REMOTE_PATH: '/'
LOCAL_PATH: '${BITBUCKET_CLONE_DIR}/docker-compose.yml'
condition:
changesets:
includePaths:
- "docker-compose.yml"
- "bitbucket-pipelines.yml"
- step:
name: Deploy to development
trigger: manual
deployment: test
script:
- pipe: atlassian/ssh-run:0.4.1
variables:
SSH_USER: 'root'
SERVER: '46.101.106.188'
COMMAND: 'docker compose pull && docker compose -p flask-app up --force-recreate -d && docker image prune -f'
- step:
name: Run migrations
script:
- pipe: atlassian/ssh-run:0.4.1
variables:
SSH_USER: 'root'
SERVER: '46.101.106.188'
COMMAND: 'docker compose -p flask-app run --rm flask poetry run flask db upgrade'
condition:
changesets:
includePaths:
- "migrations/versions/**"
# - step:
# name: Deploy to development
# deployment: Test
# script:
# - unset DOCKER_HOST
# - docker -v
# - docker compose --help
# - docker context create remote --docker "host=ssh://[email protected]"
# - docker context ls
# - docker context use remote
# - docker --context remote -p flask-app compose up -d --remove-orphans
definitions:
services:
postgres:
image: bitnami/postgresql:13-debian-11
variables:
POSTGRESQL_DATABASE: 'flask_app_test'
POSTGRESQL_USERNAME: 'flask_app_root'
POSTGRES_PASSWORD: '123456'
POSTGRESQL_POSTGRES_PASSWORD: '123456'
caches:
venv: .venv
pre-commit: $HOME/.cache/pre-commit