Newer
Older
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
138
139
stages:
- build
- deploy
.prepare_pipenv: &prepare_pipenv |
export LC_ALL=C.UTF-8
export LANG=C.UTF-8
pip install pipenv --ignore-installed
set +e
pipenv --venv; NO_VENV=$? ; echo 'No fail'
set -e
if [ $NO_VENV -eq 1 ]; then
pipenv --python 3.10
fi
#pipenv run pip install pip=="18.0"
pipenv install --dev
.prepare_awscli: &prepare_awscli |
export LC_ALL=C.UTF-8
export LANG=C.UTF-8
pip install pipenv --ignore-installed
set +e
pipenv --venv; NO_VENV=$? ; echo 'No fail'
set -e
if [ $NO_VENV -eq 1 ]; then
pipenv --python 3.10
fi
pipenv run pip install awscli
.get_ecscli: &get_ecscli |
if [ -e ecs-cli ]
then
echo "ecs-cli already downloaded"
else
apk add curl
curl -o ./ecs-cli https://amazon-ecs-cli.s3.amazonaws.com/ecs-cli-linux-amd64-latest
fi
chmod +x ecs-cli
variables:
GIT_SUBMODULE_STRATEGY: recursive
DOCKER_TLS_CERTDIR: ""
build_image_prod:
stage: build
image: docker
services:
- docker:dind
before_script:
- apk --no-cache add --virtual git build-base gcc libgcc musl-dev jpeg-dev zlib-dev libc-dev libffi-dev mariadb-dev openssl-dev python3-dev py3-pip
- *prepare_awscli
script:
- $(pipenv run aws ecr get-login --no-include-email --region eu-west-1 )
- |
set +e
docker pull "${AWS_REGISTRY_IMAGE}:$CI_BUILD_REF_NAME"
set -e
- docker build --cache-from "${AWS_REGISTRY_IMAGE}:$CI_BUILD_REF_NAME" -t "${AWS_REGISTRY_IMAGE}:$CI_BUILD_REF_NAME" .
- docker push "$AWS_REGISTRY_IMAGE:$CI_BUILD_REF_NAME"
only:
- tags
cache:
key: docker
paths:
- .venv
- .pip-cache
- Pipfile.lock
deploy_prod:
stage: deploy
image: python:3.10-alpine
environment: production
before_script:
- *get_ecscli
only:
- tags
script:
- export TAG=$CI_BUILD_REF_NAME
- source backend/production.env
- ./ecs-cli configure --region eu-west-1 --cluster spotfleet-gitlab
- ./ecs-cli compose --file ecs-compose.yml --ecs-params ecs-params.yml --project-name saf-prod service up --create-log-groups --target-group-arn $AWS_TG_ARN --container-name saf --container-port 80 --timeout 10 --role $AWS_ROLE
cache:
key: python
paths:
- .venv
- .pip-cache
- Pipfile.lock
- ecs-cli
build_image_staging:
stage: build
image: docker
services:
- docker:dind
before_script:
- apk --no-cache add --virtual git build-base gcc libgcc musl-dev jpeg-dev zlib-dev libc-dev libffi-dev mariadb-dev openssl-dev python3-dev py3-pip
- *prepare_awscli
script:
- $(pipenv run aws ecr get-login --no-include-email --region eu-west-1 )
- |
set +e
docker pull "${AWS_REGISTRY_IMAGE}:PREPROD-$CI_BUILD_REF_NAME"
set -e
- docker build --cache-from "${AWS_REGISTRY_IMAGE}:PREPROD-$CI_BUILD_REF_NAME" -t "${AWS_REGISTRY_IMAGE}:PREPROD-$CI_BUILD_REF_NAME" .
- docker push "$AWS_REGISTRY_IMAGE:PREPROD-$CI_BUILD_REF_NAME"
except:
- tags
cache:
key: docker
paths:
- .venv
- .pip-cache
- Pipfile.lock
deploy_staging:
stage: deploy
image: python:3.10-alpine
environment: staging
before_script:
- *get_ecscli
except:
- tags
script:
- export TAG=PREPROD-$CI_BUILD_REF_NAME
- source backend/staging.env
- ./ecs-cli configure --region eu-west-1 --cluster spotfleet-gitlab
- ./ecs-cli compose --file ecs-compose.yml --ecs-params ecs-params.yml --project-name saf-stag service up --create-log-groups --target-group-arn $AWS_TG_ARN --container-name saf --container-port 80 --timeout 10 --role $AWS_ROLE
cache:
key: python
paths:
- .venv
- .pip-cache
- Pipfile.lock
- ecs-cli