mirror of
https://github.com/sergeyyarkov/astro-directus-example.git
synced 2026-10-11 02:08:57 +03:00
deploy script
This commit is contained in:
parent
a2f85b4275
commit
33318012fc
@ -3,17 +3,16 @@ services:
|
||||
web:
|
||||
build:
|
||||
context: ./website
|
||||
target: production
|
||||
network: host
|
||||
target: production
|
||||
extra_hosts:
|
||||
- 'cms.localhost:127.0.0.1'
|
||||
container_name: web
|
||||
volumes:
|
||||
- ./website:/app:rw
|
||||
depends_on:
|
||||
- directus
|
||||
args:
|
||||
- 'CACHE_DATE=$(date +%Y-%m-%d:%H:%M:%S)'
|
||||
networks:
|
||||
- directus
|
||||
volumes:
|
||||
- './website/nginx/conf.d:/etc/nginx/conf.d:rw'
|
||||
env_file:
|
||||
- ./website/.env
|
||||
|
||||
@ -22,7 +21,7 @@ services:
|
||||
container_name: nginx
|
||||
image: nginx:1.23.3-alpine
|
||||
volumes:
|
||||
- './nginx/nginx.conf:/etc/nginx/nginx.conf'
|
||||
- './nginx/nginx.conf:/etc/nginx/nginx.conf:rw'
|
||||
ports:
|
||||
- '80:80'
|
||||
- '433:433'
|
||||
|
||||
46
compose.yml
46
compose.yml
@ -3,29 +3,27 @@ services:
|
||||
web:
|
||||
build:
|
||||
context: ./website
|
||||
network: host
|
||||
target: production
|
||||
container_name: web
|
||||
volumes:
|
||||
- './website/nginx/conf.d:/etc/nginx/conf.d:rw'
|
||||
extra_hosts:
|
||||
- 'cms.localhost:127.0.0.1'
|
||||
args:
|
||||
- 'CACHE_DATE=$(date +%Y-%m-%d:%H:%M:%S)'
|
||||
networks:
|
||||
- directus
|
||||
ports:
|
||||
- '80'
|
||||
depends_on:
|
||||
- directus
|
||||
- nginx
|
||||
environment:
|
||||
- DIRECTUS_URL=http://cms.localhost
|
||||
- DIRECTUS_EMAIL=admin@example.com
|
||||
- DIRECTUS_PASSWORD=d1r3ctu5
|
||||
- DIRECTUS_STATIC_TOKEN=
|
||||
- '3000'
|
||||
volumes:
|
||||
- './website/nginx/conf.d:/etc/nginx/conf.d:rw'
|
||||
env_file:
|
||||
- ./website/.env
|
||||
|
||||
nginx:
|
||||
restart: 'always'
|
||||
# restart: 'always'
|
||||
container_name: nginx
|
||||
image: nginx:1.23.3-alpine
|
||||
volumes:
|
||||
- './nginx/nginx.conf:/etc/nginx/nginx.conf'
|
||||
- './nginx/nginx.conf:/etc/nginx/nginx.conf:rw'
|
||||
ports:
|
||||
- '80:80'
|
||||
- '433:433'
|
||||
@ -44,20 +42,14 @@ services:
|
||||
volumes:
|
||||
- db-data:/var/lib/postgresql/data
|
||||
ports:
|
||||
- 5432
|
||||
- 5432:5432
|
||||
networks:
|
||||
- directus
|
||||
|
||||
# cache:
|
||||
# container_name: cache
|
||||
# image: redis:6
|
||||
# networks:
|
||||
# - directus
|
||||
|
||||
directus:
|
||||
image: directus/directus:latest
|
||||
image: directus/directus:10.0.0
|
||||
ports:
|
||||
- 8055
|
||||
- 8055:8055
|
||||
volumes:
|
||||
- uploads:/directus/uploads
|
||||
depends_on:
|
||||
@ -67,20 +59,13 @@ services:
|
||||
environment:
|
||||
KEY: '255d861b-5ea1-5996-9aa3-922530ec40b1'
|
||||
SECRET: '6116487b-cda1-52c2-b5b5-c8022c45e263'
|
||||
|
||||
MAX_PAYLOAD_SIZE: '100mb'
|
||||
|
||||
DB_CLIENT: 'pg'
|
||||
DB_HOST: 'database'
|
||||
DB_PORT: '5432'
|
||||
DB_DATABASE: 'directus'
|
||||
DB_USER: 'directus'
|
||||
DB_PASSWORD: 'directus'
|
||||
|
||||
# CACHE_ENABLED: 'false'
|
||||
# CACHE_STORE: 'redis'
|
||||
# CACHE_REDIS: 'redis://cache:6379'
|
||||
|
||||
ADMIN_EMAIL: 'admin@example.com'
|
||||
ADMIN_PASSWORD: 'd1r3ctu5'
|
||||
volumes:
|
||||
@ -88,3 +73,4 @@ volumes:
|
||||
uploads:
|
||||
networks:
|
||||
directus:
|
||||
driver: bridge
|
||||
|
||||
38
scripts/deploy-web.sh
Executable file
38
scripts/deploy-web.sh
Executable file
@ -0,0 +1,38 @@
|
||||
#!bin/bash
|
||||
|
||||
reload_nginx() {
|
||||
docker exec nginx nginx -s reload
|
||||
}
|
||||
|
||||
rebuild_web() {
|
||||
docker compose build --build-arg CACHE_DATE=$(date +%Y-%m-%d:%H:%M:%S) --progress=plain web
|
||||
}
|
||||
|
||||
zero_downtime_deploy() {
|
||||
service_name=web
|
||||
old_container_id=$(docker ps -f name=$service_name -q | tail -n1)
|
||||
|
||||
# bring a new container online, running new code
|
||||
# (nginx continues routing to the old container only)
|
||||
docker compose up -d --no-deps --scale $service_name=2 --no-recreate $service_name
|
||||
|
||||
# wait for new container to be available
|
||||
new_container_id=$(docker ps -f name=$service_name -q | head -n1)
|
||||
new_container_ip=$(docker inspect -f '{{range.NetworkSettings.Networks}}{{.IPAddress}}{{end}}' $new_container_id)
|
||||
curl --silent -I --retry-connrefused --retry 30 --retry-delay 1 --fail http://$new_container_ip:80/ || exit 1
|
||||
|
||||
# start routing requests to the new container (as well as the old)
|
||||
reload_nginx
|
||||
|
||||
# take the old container offline
|
||||
docker stop $old_container_id
|
||||
docker rm $old_container_id
|
||||
|
||||
docker compose up -d --no-deps --scale $service_name=1 --no-recreate $service_name
|
||||
|
||||
# stop routing requests to the old container
|
||||
reload_nginx
|
||||
}
|
||||
|
||||
rebuild_web
|
||||
zero_downtime_deploy
|
||||
4
scripts/hello.sh
Normal file → Executable file
4
scripts/hello.sh
Normal file → Executable file
@ -1,3 +1,7 @@
|
||||
#!bin/bash
|
||||
|
||||
say_hello() {
|
||||
echo "Hello!"
|
||||
}
|
||||
|
||||
say_hello
|
||||
@ -3,30 +3,29 @@
|
||||
ARG NODE_IMAGE=node:19-alpine3.16
|
||||
ARG NGINX_IMAGE=nginx:1.23.3-alpine
|
||||
|
||||
# DEVELOPMENT STAGE
|
||||
FROM ${NODE_IMAGE} as development
|
||||
WORKDIR /app
|
||||
COPY ./package.json ./
|
||||
COPY ./package-lock.json ./
|
||||
|
||||
RUN npm ci
|
||||
RUN npm ci && npm cache clean --force
|
||||
|
||||
COPY . .
|
||||
|
||||
EXPOSE 3000
|
||||
CMD [ "npm", "start" ]
|
||||
|
||||
# BUILDER STAGE
|
||||
ARG CACHE_DATE=not_a_date
|
||||
|
||||
FROM development as builder
|
||||
ENV DIRECTUS_URL=http://cms.localhost
|
||||
WORKDIR /app
|
||||
ENV DIRECTUS_URL=http://cms.localhost
|
||||
RUN npm run build
|
||||
|
||||
# PRODUCTION STAGE
|
||||
FROM ${NGINX_IMAGE} as production
|
||||
|
||||
COPY --from=builder /app/dist /usr/share/nginx/html
|
||||
COPY --from=builder /app/nginx/conf.d /etc/nginx/conf.d
|
||||
COPY --from=builder /app/dist /usr/share/nginx/html
|
||||
|
||||
EXPOSE 80
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user