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:
|
web:
|
||||||
build:
|
build:
|
||||||
context: ./website
|
context: ./website
|
||||||
target: production
|
|
||||||
network: host
|
network: host
|
||||||
|
target: production
|
||||||
extra_hosts:
|
extra_hosts:
|
||||||
- 'cms.localhost:127.0.0.1'
|
- 'cms.localhost:127.0.0.1'
|
||||||
container_name: web
|
args:
|
||||||
volumes:
|
- 'CACHE_DATE=$(date +%Y-%m-%d:%H:%M:%S)'
|
||||||
- ./website:/app:rw
|
|
||||||
depends_on:
|
|
||||||
- directus
|
|
||||||
networks:
|
networks:
|
||||||
- directus
|
- directus
|
||||||
|
volumes:
|
||||||
|
- './website/nginx/conf.d:/etc/nginx/conf.d:rw'
|
||||||
env_file:
|
env_file:
|
||||||
- ./website/.env
|
- ./website/.env
|
||||||
|
|
||||||
@ -22,7 +21,7 @@ services:
|
|||||||
container_name: nginx
|
container_name: nginx
|
||||||
image: nginx:1.23.3-alpine
|
image: nginx:1.23.3-alpine
|
||||||
volumes:
|
volumes:
|
||||||
- './nginx/nginx.conf:/etc/nginx/nginx.conf'
|
- './nginx/nginx.conf:/etc/nginx/nginx.conf:rw'
|
||||||
ports:
|
ports:
|
||||||
- '80:80'
|
- '80:80'
|
||||||
- '433:433'
|
- '433:433'
|
||||||
|
|||||||
46
compose.yml
46
compose.yml
@ -3,29 +3,27 @@ services:
|
|||||||
web:
|
web:
|
||||||
build:
|
build:
|
||||||
context: ./website
|
context: ./website
|
||||||
|
network: host
|
||||||
target: production
|
target: production
|
||||||
container_name: web
|
extra_hosts:
|
||||||
volumes:
|
- 'cms.localhost:127.0.0.1'
|
||||||
- './website/nginx/conf.d:/etc/nginx/conf.d:rw'
|
args:
|
||||||
|
- 'CACHE_DATE=$(date +%Y-%m-%d:%H:%M:%S)'
|
||||||
networks:
|
networks:
|
||||||
- directus
|
- directus
|
||||||
ports:
|
ports:
|
||||||
- '80'
|
- '3000'
|
||||||
depends_on:
|
volumes:
|
||||||
- directus
|
- './website/nginx/conf.d:/etc/nginx/conf.d:rw'
|
||||||
- nginx
|
env_file:
|
||||||
environment:
|
- ./website/.env
|
||||||
- DIRECTUS_URL=http://cms.localhost
|
|
||||||
- DIRECTUS_EMAIL=admin@example.com
|
|
||||||
- DIRECTUS_PASSWORD=d1r3ctu5
|
|
||||||
- DIRECTUS_STATIC_TOKEN=
|
|
||||||
|
|
||||||
nginx:
|
nginx:
|
||||||
restart: 'always'
|
# restart: 'always'
|
||||||
container_name: nginx
|
container_name: nginx
|
||||||
image: nginx:1.23.3-alpine
|
image: nginx:1.23.3-alpine
|
||||||
volumes:
|
volumes:
|
||||||
- './nginx/nginx.conf:/etc/nginx/nginx.conf'
|
- './nginx/nginx.conf:/etc/nginx/nginx.conf:rw'
|
||||||
ports:
|
ports:
|
||||||
- '80:80'
|
- '80:80'
|
||||||
- '433:433'
|
- '433:433'
|
||||||
@ -44,20 +42,14 @@ services:
|
|||||||
volumes:
|
volumes:
|
||||||
- db-data:/var/lib/postgresql/data
|
- db-data:/var/lib/postgresql/data
|
||||||
ports:
|
ports:
|
||||||
- 5432
|
- 5432:5432
|
||||||
networks:
|
networks:
|
||||||
- directus
|
- directus
|
||||||
|
|
||||||
# cache:
|
|
||||||
# container_name: cache
|
|
||||||
# image: redis:6
|
|
||||||
# networks:
|
|
||||||
# - directus
|
|
||||||
|
|
||||||
directus:
|
directus:
|
||||||
image: directus/directus:latest
|
image: directus/directus:10.0.0
|
||||||
ports:
|
ports:
|
||||||
- 8055
|
- 8055:8055
|
||||||
volumes:
|
volumes:
|
||||||
- uploads:/directus/uploads
|
- uploads:/directus/uploads
|
||||||
depends_on:
|
depends_on:
|
||||||
@ -67,20 +59,13 @@ services:
|
|||||||
environment:
|
environment:
|
||||||
KEY: '255d861b-5ea1-5996-9aa3-922530ec40b1'
|
KEY: '255d861b-5ea1-5996-9aa3-922530ec40b1'
|
||||||
SECRET: '6116487b-cda1-52c2-b5b5-c8022c45e263'
|
SECRET: '6116487b-cda1-52c2-b5b5-c8022c45e263'
|
||||||
|
|
||||||
MAX_PAYLOAD_SIZE: '100mb'
|
MAX_PAYLOAD_SIZE: '100mb'
|
||||||
|
|
||||||
DB_CLIENT: 'pg'
|
DB_CLIENT: 'pg'
|
||||||
DB_HOST: 'database'
|
DB_HOST: 'database'
|
||||||
DB_PORT: '5432'
|
DB_PORT: '5432'
|
||||||
DB_DATABASE: 'directus'
|
DB_DATABASE: 'directus'
|
||||||
DB_USER: 'directus'
|
DB_USER: 'directus'
|
||||||
DB_PASSWORD: 'directus'
|
DB_PASSWORD: 'directus'
|
||||||
|
|
||||||
# CACHE_ENABLED: 'false'
|
|
||||||
# CACHE_STORE: 'redis'
|
|
||||||
# CACHE_REDIS: 'redis://cache:6379'
|
|
||||||
|
|
||||||
ADMIN_EMAIL: 'admin@example.com'
|
ADMIN_EMAIL: 'admin@example.com'
|
||||||
ADMIN_PASSWORD: 'd1r3ctu5'
|
ADMIN_PASSWORD: 'd1r3ctu5'
|
||||||
volumes:
|
volumes:
|
||||||
@ -88,3 +73,4 @@ volumes:
|
|||||||
uploads:
|
uploads:
|
||||||
networks:
|
networks:
|
||||||
directus:
|
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
|
||||||
6
scripts/hello.sh
Normal file → Executable file
6
scripts/hello.sh
Normal file → Executable file
@ -1,3 +1,7 @@
|
|||||||
#!bin/bash
|
#!bin/bash
|
||||||
|
|
||||||
echo "Hello!"
|
say_hello() {
|
||||||
|
echo "Hello!"
|
||||||
|
}
|
||||||
|
|
||||||
|
say_hello
|
||||||
@ -3,31 +3,30 @@
|
|||||||
ARG NODE_IMAGE=node:19-alpine3.16
|
ARG NODE_IMAGE=node:19-alpine3.16
|
||||||
ARG NGINX_IMAGE=nginx:1.23.3-alpine
|
ARG NGINX_IMAGE=nginx:1.23.3-alpine
|
||||||
|
|
||||||
# DEVELOPMENT STAGE
|
|
||||||
FROM ${NODE_IMAGE} as development
|
FROM ${NODE_IMAGE} as development
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
COPY ./package.json ./
|
COPY ./package.json ./
|
||||||
COPY ./package-lock.json ./
|
COPY ./package-lock.json ./
|
||||||
|
|
||||||
RUN npm ci
|
RUN npm ci && npm cache clean --force
|
||||||
|
|
||||||
COPY . .
|
COPY . .
|
||||||
|
|
||||||
EXPOSE 3000
|
EXPOSE 3000
|
||||||
CMD [ "npm", "start" ]
|
CMD [ "npm", "start" ]
|
||||||
|
|
||||||
# BUILDER STAGE
|
ARG CACHE_DATE=not_a_date
|
||||||
|
|
||||||
FROM development as builder
|
FROM development as builder
|
||||||
ENV DIRECTUS_URL=http://cms.localhost
|
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
ENV DIRECTUS_URL=http://cms.localhost
|
||||||
RUN npm run build
|
RUN npm run build
|
||||||
|
|
||||||
# PRODUCTION STAGE
|
|
||||||
FROM ${NGINX_IMAGE} as production
|
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/nginx/conf.d /etc/nginx/conf.d
|
||||||
|
COPY --from=builder /app/dist /usr/share/nginx/html
|
||||||
|
|
||||||
EXPOSE 80
|
EXPOSE 80
|
||||||
|
|
||||||
CMD ["nginx", "-g", "daemon off;"]
|
CMD ["nginx", "-g", "daemon off;"]
|
||||||
Loading…
x
Reference in New Issue
Block a user