Skip to content

Commit c168ce5

Browse files
committed
feat: linux provider
1 parent ff0b35d commit c168ce5

File tree

5 files changed

+340
-51
lines changed

5 files changed

+340
-51
lines changed

docker-compose-remote.yaml

Lines changed: 222 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,222 @@
1+
version: '3.5'
2+
services:
3+
server-template-ingress:
4+
container_name: server-template-ingress
5+
image: nginx:1.15-alpine
6+
restart: unless-stopped
7+
networks:
8+
- default
9+
ports:
10+
# __IMAGE_TAG__
11+
- "__PORT__:80"
12+
volumes:
13+
- "./docker-nginx.conf:/etc/nginx/nginx.conf:delegated"
14+
- "./docker-nginx.htpasswd:/etc/nginx/.htpasswd:delegated"
15+
16+
server-template-admin:
17+
container_name: server-template-admin
18+
build:
19+
context: ./admin
20+
dockerfile: ${dockerfile}
21+
restart: unless-stopped
22+
networks:
23+
- default
24+
ports:
25+
- "8080"
26+
volumes:
27+
- "./admin:/service:delegated"
28+
- "./shared:/service/shared:delegated"
29+
- "/service/node_modules"
30+
environment:
31+
COMMON_COMPANY: companyname
32+
COMMON_PROJECT: server-template
33+
34+
server-template-client:
35+
container_name: server-template-client
36+
build:
37+
context: ./client
38+
dockerfile: ${dockerfile}
39+
restart: unless-stopped
40+
networks:
41+
- default
42+
ports:
43+
- "8080"
44+
volumes:
45+
- "./client:/service:delegated"
46+
- "./shared:/service/shared:delegated"
47+
- "/service/node_modules"
48+
secrets:
49+
# NOTE: Database connection is for tests only
50+
- DATABASE_PASSWORD
51+
- EXAMPLE_SECRET
52+
environment:
53+
COMMON_COMPANY: companyname
54+
COMMON_PROJECT: server-template
55+
# NOTE: Database connection is for tests only
56+
DATABASE_HOST: server-template-database
57+
DATABASE_NAME: server_template_local
58+
DATABASE_USER: server_template_local_app
59+
60+
server-template-graphql:
61+
container_name: server-template-graphql
62+
build:
63+
context: ./graphql
64+
dockerfile: ${dockerfile}
65+
restart: unless-stopped
66+
networks:
67+
- default
68+
ports:
69+
- "8080"
70+
volumes:
71+
- "./graphql:/service:delegated"
72+
- "./shared:/service/shared:delegated"
73+
- "/service/node_modules"
74+
environment:
75+
COMMON_COMPANY: companyname
76+
COMMON_PROJECT: server-template
77+
COMMON_DOMAIN: localhost
78+
COMMON_URL: http://localhost:9999
79+
COMMON_DEBUG: 'false'
80+
COMMON_LOG_FORMAT: text
81+
COMMON_LOG_LEVEL: info # trace, debug, info, warn, error, fatal
82+
COMMON_ENV: local
83+
DEBUG: 'false'
84+
GRAPHQL_PORT: 8080
85+
GRAPHQL_BINDADDR: 0.0.0.0
86+
API_HOST: server-template-server
87+
API_PORT: 8080
88+
89+
server-template-server:
90+
container_name: server-template-server
91+
build:
92+
context: ./server
93+
dockerfile: ${dockerfile}
94+
restart: unless-stopped
95+
networks:
96+
- default
97+
ports:
98+
- "8080"
99+
volumes:
100+
- "./server:/service:delegated"
101+
- "./shared:/service/shared:delegated"
102+
- "/service/node_modules"
103+
secrets:
104+
- DATABASE_PASSWORD
105+
- S3_KEY_SECRET
106+
- EXAMPLE_SECRET
107+
environment:
108+
COMMON_COMPANY: companyname
109+
COMMON_PROJECT: server-template
110+
COMMON_DEBUG: 'false'
111+
COMMON_LOG_FORMAT: text
112+
COMMON_LOG_LEVEL: info # trace, debug, info, warn, error, fatal
113+
COMMON_ENV: local
114+
DEBUG: 'false'
115+
SENTRY_DSN: #sentryDSN
116+
API_PORT: 8080
117+
API_BINDADDR: 0.0.0.0
118+
KAFKA_HOST: server-template-kafka
119+
KAFKA_PORT: 9092
120+
DATABASE_HOST: server-template-database
121+
DATABASE_NAME: server_template_local
122+
DATABASE_USER: server_template_local_app
123+
DATABASE_POOL_MIN: '1'
124+
DATABASE_POOL_MAX: '10'
125+
S3_URL: http://server-template-storage:9000/
126+
S3_REGION: milkyway
127+
S3_BUCKET: bucket
128+
S3_KEY_ID: minio
129+
130+
server-template-www:
131+
container_name: server-template-www
132+
build:
133+
context: ./www
134+
dockerfile: ${dockerfile}
135+
restart: unless-stopped
136+
networks:
137+
- default
138+
ports:
139+
# TODO: Temporary hack for https://github.com/gatsbyjs/gatsby/issues/3721
140+
- "7463:8080"
141+
volumes:
142+
- "./www:/service:delegated"
143+
- "/service/node_modules"
144+
- "/service/site/node_modules"
145+
# FOR GATSBY ONLY:
146+
# - "/service/site/node_modules"
147+
148+
server-template-cache:
149+
container_name: server-template-cache
150+
image: redis:5.0-alpine
151+
restart: unless-stopped
152+
networks:
153+
- default
154+
ports:
155+
- "6379"
156+
157+
server-template-kafka:
158+
container_name: server-template-kafka
159+
image: 'bitnami/kafka:latest'
160+
ports:
161+
- '9092'
162+
environment:
163+
- KAFKA_ZOOKEEPER_CONNECT=server-template-zookeeper:2181
164+
- ALLOW_PLAINTEXT_LISTENER=yes
165+
166+
server-template-zookeeper:
167+
container_name: server-template-zookeeper
168+
image: 'bitnami/zookeeper:latest'
169+
ports:
170+
- '2181'
171+
environment:
172+
- ALLOW_ANONYMOUS_LOGIN=yes
173+
174+
# "EXTERNAL RESOURCES"
175+
176+
server-template-database:
177+
container_name: server-template-database
178+
image: postgres:9.6
179+
restart: unless-stopped
180+
networks:
181+
- default
182+
ports:
183+
- "6000:5432"
184+
secrets:
185+
- DATABASE_PASSWORD
186+
environment:
187+
POSTGRES_DB: server_template_local
188+
POSTGRES_USER: server_template_local_app
189+
POSTGRES_PASSWORD_FILE: /run/secrets/DATABASE_PASSWORD
190+
volumes:
191+
- "./database:/docker-entrypoint-initdb.d:delegated"
192+
193+
server-template-storage:
194+
container_name: server-template-storage
195+
build:
196+
context: ./storage
197+
dockerfile: ${dockerfile}
198+
restart: unless-stopped
199+
command: server /service
200+
networks:
201+
- default
202+
ports:
203+
- "9000"
204+
secrets:
205+
- S3_KEY_SECRET
206+
environment:
207+
MINIO_ACCESS_KEY: minio
208+
# MINIO requires key as environment variable?
209+
MINIO_SECRET_KEY: secret1234
210+
211+
secrets:
212+
DATABASE_PASSWORD:
213+
file: ./secrets/${taito_env}/${db_database_name}-db-app.password
214+
S3_KEY_SECRET:
215+
file: ./secrets/${taito_env}/${taito_project}-${taito_env}-storage-gateway.secret
216+
EXAMPLE_SECRET:
217+
file: ./secrets/${taito_env}/${taito_project}-${taito_env}-example.secret
218+
219+
networks:
220+
default:
221+
222+
# EOF

scripts/linux-provider/taito-deployment-deploy#post.sh

Lines changed: 49 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,30 +3,61 @@
33
: "${taito_ssh_user:?}"
44
: "${taito_host:?}"
55
: "${taito_host_dir:?}"
6+
: "${taito_namespace:?}"
7+
: "${taito_target_env:?}"
68

79
image_tag=$1
8-
# TODO PORT
9-
taito_ingress_port=8080
10+
if [[ ! $image_tag ]]; then
11+
image_tag=$(git rev-parse "${taito_branch:-dev}")
12+
echo "Image tag not given. Using commit sha $image_tag as image tag."
13+
echo
14+
fi
15+
16+
echo
17+
echo "NOTE: Deployment is done using the taito-config.sh and"
18+
echo "docker-compose-remote.yaml currently located on your local directory."
19+
echo
1020

1121
. "${taito_cli_path}/plugins/ssh/util/opts.sh"
1222

13-
echo "Copying docker-compose-prod.yaml to ${taito_host}:/${taito_host_dir}"
14-
sed "s/__IMAGE_TAG__/${image_tag}" docker-compose-prod.yaml |
15-
sed "s/__PORT__/${taito_ingress_port}" \
16-
> docker-compose-prod.yaml.tmp
23+
echo "[Copy docker-compose-remote.yaml to ${taito_host}:/tmp]"
1724
(
1825
${taito_setv:?}
19-
scp ${opts} docker-compose-prod.yaml.tmp \
20-
"${taito_ssh_user}@${taito_host}:${taito_host_dir}/docker-compose-prod.yaml"
26+
mkdir -p tmp
27+
tar -cf "tmp/${taito_namespace}.tar" docker-compose-remote.yaml taito-config.sh
28+
scp ${opts} "tmp/${taito_namespace}.tar" "${taito_ssh_user}@${taito_host}:/tmp"
29+
rm -f "tmp/${taito_namespace}.tar"
2130
)
22-
rm -f docker-compose-prod.yaml.tmp
31+
echo
2332

24-
echo "Restarting docker-compose on ${taito_host}:/${taito_host_dir}"
25-
(
26-
${taito_setv:?}
27-
ssh ${opts} "${taito_ssh_user}@${taito_host}" "
28-
sudo bash -c '
29-
cd ${taito_host_dir} && docker-compose stop && docker-compose -d up
30-
'
31-
"
32-
)
33+
echo "[Execute on ${taito_host}]"
34+
ssh ${opts} "${taito_ssh_user}@${taito_host}" "
35+
sudo bash -c '
36+
${taito_setv:?} &&
37+
cd ${taito_host_dir} &&
38+
echo &&
39+
echo [Extract /tmp/${taito_namespace}.tar] &&
40+
tar -xf /tmp/${taito_namespace}.tar -C . &&
41+
rm -f /tmp/${taito_namespace}.tar &&
42+
echo &&
43+
echo [Replace port and image tag in docker-compose-remote.yaml] &&
44+
PORT=\$(getsiteport ${taito_namespace}) &&
45+
sed -i s/__PORT__/\${PORT}/ docker-compose-remote.yaml &&
46+
sed -i s/__IMAGE_TAG__/${image_tag}/ docker-compose-remote.yaml &&
47+
echo &&
48+
echo [Set environment in taito-config.sh] &&
49+
sed -i \"1 ataito_target_env=${taito_target_env}\" taito-config.sh &&
50+
sed -i /taito_util_path/d taito-config.sh &&
51+
echo &&
52+
echo [Set environment variables] &&
53+
set -a &&
54+
taito_target_env=${taito_target_env} &&
55+
. taito-config.sh &&
56+
set +a &&
57+
echo &&
58+
echo [Restart docker-compose] &&
59+
docker-compose -f docker-compose-remote.yaml stop &&
60+
docker-compose -f docker-compose-remote.yaml -d up
61+
'
62+
"
63+
echo

scripts/linux-provider/taito-env-apply#post.sh

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3,40 +3,41 @@
33
: "${taito_ssh_user:?}"
44
: "${taito_host:?}"
55
: "${taito_host_dir:?}"
6+
: "${taito_env:?}"
7+
: "${taito_namespace:?}"
8+
: "${taito_domain:?}"
69

7-
TEMPLATE=/etc/nginx/templates/taito-site-template
8-
CLIENT_MAX_BODY_SIZE=32m
9-
# TODO PORT
10-
taito_ingress_port=8080
10+
CLIENT_MAX_BODY_SIZE=1m
1111

1212
. "${taito_cli_path}/plugins/ssh/util/opts.sh"
1313

14-
${taito_setv:?}
14+
echo "[Copy changed secrets to ${taito_host}:/tmp]"
15+
(
16+
${taito_setv:?}
17+
mkdir -p tmp
18+
tar -cf "tmp/${taito_namespace}-secrets.tar" -C "secrets/changed/${taito_env}" .
19+
scp ${opts} "tmp/${taito_namespace}-secrets.tar" "${taito_ssh_user}@${taito_host}:/tmp"
20+
rm -f "tmp/${taito_namespace}-secrets.tar"
21+
)
22+
echo
23+
24+
echo "[Execute on ${taito_host}]"
1525
ssh ${opts} "${taito_ssh_user}@${taito_host}" "
1626
sudo bash -c '
17-
echo Making sure ${taito_host_dir} directory exists on host ${taito_host} &&
18-
mkdir -p ${taito_host_dir} &&
19-
if [[ -f $TEMPLATE ]]; then
20-
echo Add site ${taito_namespace} and restart nginx &&
21-
sed s/NAME/${taito_namespace}/g $TEMPLATE | \
22-
sed s/DOMAIN/${taito_domain}/g | \
23-
sed s/PORT/${taito_ingress_port}/g | \
24-
sed s/CLIENT_MAX_BODY_SIZE/${CLIENT_MAX_BODY_SIZE}/g \
25-
> /etc/nginx/sites-available/${taito_namespace} &&
26-
rm -f /etc/nginx/sites-enabled/${taito_namespace} &&
27-
ln -s /etc/nginx/sites-available/${taito_namespace} \
28-
/etc/nginx/sites-enabled/${taito_namespace} &&
29-
service nginx restart;
27+
${taito_setv:?} &&
28+
echo [Extract /tmp/${taito_namespace}-secrets.tar] &&
29+
mkdir -p ${taito_host_dir}/secrets/${taito_env} &&
30+
tar -xf /tmp/${taito_namespace}-secrets.tar -C ${taito_host_dir}/secrets/${taito_env} &&
31+
rm -f /tmp/${taito_namespace}-secrets.tar &&
32+
echo &&
33+
34+
if which createsite &> /dev/null; then
35+
createsite ${taito_namespace} ${taito_domain} $CLIENT_MAX_BODY_SIZE;
3036
else
31-
echo File $TEMPLATE does not exist. &&
37+
echo NOTE: createsite command does not exist. &&
3238
echo Configure routing for domain ${taito_domain} yourself. &&
3339
echo Press enter to continue &&
3440
read -r;
3541
fi
3642
'
3743
"
38-
39-
# |
40-
# sed s/DOMAIN/${taito_domain}/g |
41-
# sed s/PORT/${taito_ingress_port}/g |
42-
# sed s/CLIENT_MAX_BODY_SIZE/${CLIENT_MAX_BODY_SIZE}/g \

scripts/linux-provider/taito-env-destroy#post.sh

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,20 @@
11
#!/bin/bash
22
: "${taito_cli_path:?}"
3+
: "${taito_namespace:?}"
34
: "${taito_ssh_user:?}"
45
: "${taito_host:?}"
56
: "${taito_host_dir:?}"
67

78
. "${taito_cli_path}/plugins/ssh/util/opts.sh"
89

9-
${taito_setv:?}
10+
echo "[Execute on ${taito_host}]"
1011
ssh ${opts} "${taito_ssh_user}@${taito_host}" "
1112
sudo bash -c '
12-
echo Delete directory ${taito_host_dir} &&
13-
rm -rf ${taito_host_dir} &&
14-
if [[ -f /etc/nginx/sites-available/${taito_namespace} ]]; then
15-
echo Delete site ${taito_namespace} and restart nginx &&
16-
rm -f /etc/nginx/sites-enabled/${taito_namespace} &&
17-
rm -f /etc/nginx/sites-available/${taito_namespace} &&
18-
service nginx restart;
13+
${taito_setv:?} &&
14+
if which deletesite &> /dev/null; then
15+
deletesite ${taito_namespace};
1916
else
20-
echo File /etc/nginx/sites-available/${taito_namespace} does not exist. &&
17+
echo NOTE: deletesite command does not exist. &&
2118
echo You have to remove routing for domain ${taito_domain} yourself. &&
2219
echo Press enter to continue. &&
2320
read -r;

0 commit comments

Comments
 (0)