Skip to content

Commit

Permalink
ci(npcs): update
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaosen7 committed Aug 1, 2024
1 parent d6cec74 commit c2295ec
Show file tree
Hide file tree
Showing 8 changed files with 147 additions and 7 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/docker-deploy-staging.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
username: ${{ secrets.VPS_USER_STAGING }}
key: ${{ secrets.VPS_SSH_KEY_STAGING }}
port: ${{ secrets.VPS_PORT_STAGING }}
source: ./deploy
source: ./deploy/staging
target: ${{ secrets.VPS_WORK_DIR_STAGING }}

- name: Execute deployment via SSH
Expand All @@ -30,7 +30,7 @@ jobs:
key: ${{ secrets.VPS_SSH_KEY_STAGING }}
port: ${{ secrets.VPS_PORT_STAGING }}
script: |
cd ${{ secrets.VPS_WORK_DIR_STAGING }}/deploy
cd ${{ secrets.VPS_WORK_DIR_STAGING }}/deploy/staging
export $(grep -v '^#' ~/.env.local | xargs)
docker compose pull ${{ github.event.client_payload.app }}
docker compose up -d ${{ github.event.client_payload.app }}
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/docker-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
username: ${{ secrets.VPS_USER }}
key: ${{ secrets.VPS_SSH_KEY }}
port: ${{ secrets.VPS_PORT }}
source: ./deploy
source: ./deploy/production
target: ${{ secrets.VPS_WORK_DIR }}

- name: Execute deployment via SSH
Expand All @@ -30,7 +30,7 @@ jobs:
key: ${{ secrets.VPS_SSH_KEY }}
port: ${{ secrets.VPS_PORT }}
script: |
cd ${{ secrets.VPS_WORK_DIR }}/deploy
cd ${{ secrets.VPS_WORK_DIR }}/deploy/production
export $(grep -v '^#' ~/.env.local | xargs)
docker compose pull ${{ github.event.client_payload.app }}
docker compose up -d ${{ github.event.client_payload.app }}
Expand Down
File renamed without changes.
22 changes: 22 additions & 0 deletions deploy/production/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# next.js-practical-cases - deploy production

## Deploy by hand

### Cheat sheet

```bash
# Load env vars
export $(grep -v '^#' ~/.env.local | xargs)
# Pull the latest image
docker compose pull <app>
# Restart container
docker compose up -d <app>
# Clear unused images
docker image prune -f
```

To kill all containers in current machine.

```bash
docker kill $(docker ps -q) && docker rm $(docker ps -a -q)
```
22 changes: 20 additions & 2 deletions deploy/docker-compose.yml → deploy/production/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: nextjs-prictical-cases
version: "3.8"

services:
template:
Expand All @@ -10,7 +10,7 @@ services:
- CLERK_SECRET_KEY
- NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY
ports:
- 80:3000
- 3000:3000
depends_on:
postgres:
condition: service_healthy
Expand Down Expand Up @@ -74,3 +74,21 @@ services:
retries: 5
volumes:
- ./volumes/pgdata:/var/lib/postgresql/data

nginx:
container_name: nginx
image: nginx:latest
ports:
- "80:80"
- "443:443"
volumes:
- ./volumes/nginx.conf:/etc/nginx/nginx.conf:ro
depends_on:
- template
- notes
- stackoverflow
- large-file-upload

networks:
default:
driver: bridge
6 changes: 6 additions & 0 deletions deploy/staging/.env.local.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
DOCKER_REGISTRY=
DOCKER_USER=
DOCKER_PASSWORD=
POSTGRES_PASSWORD=
NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY=
CLERK_SECRET_KEY=
2 changes: 1 addition & 1 deletion deploy/README.md → deploy/staging/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# next.js-practical-cases - deploy
# next.js-practical-cases - deploy staging

## Deploy by hand

Expand Down
94 changes: 94 additions & 0 deletions deploy/staging/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
version: "3.8"

services:
template:
container_name: template
image: $DOCKER_REGISTRY/$DOCKER_USER/npcs-template:$DOCKER_TAG
restart: always
environment:
- DATABASE_URL=postgresql://postgres:${POSTGRES_PASSWORD}@postgres:5432/template?pool_timeout=6000
- CLERK_SECRET_KEY
- NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY
ports:
- 3000:3000
depends_on:
postgres:
condition: service_healthy

notes:
container_name: notes
image: $DOCKER_REGISTRY/$DOCKER_USER/npcs-notes:$DOCKER_TAG
restart: always
environment:
- DATABASE_URL=postgresql://postgres:${POSTGRES_PASSWORD}@postgres:5432/notes?pool_timeout=6000
- CLERK_SECRET_KEY
- NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY
ports:
- 3001:3000
depends_on:
postgres:
condition: service_healthy

stackoverflow:
container_name: stackoverflow
image: $DOCKER_REGISTRY/$DOCKER_USER/npcs-stackoverflow:$DOCKER_TAG
restart: always
environment:
- DATABASE_URL=postgresql://postgres:${POSTGRES_PASSWORD}@postgres:5432/stackoverflow?pool_timeout=6000
- CLERK_SECRET_KEY
- NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY
ports:
- 3002:3000
depends_on:
postgres:
condition: service_healthy

large-file-upload:
container_name: large-file-upload
image: $DOCKER_REGISTRY/$DOCKER_USER/npcs-large-file-upload:$DOCKER_TAG
restart: always
environment:
- DATABASE_URL=postgresql://postgres:${POSTGRES_PASSWORD}@postgres:5432/large-file-upload?pool_timeout=6000
- CLERK_SECRET_KEY
- NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY
ports:
- 3003:3000
- 9999:9999
depends_on:
postgres:
condition: service_healthy

postgres:
container_name: postgres
image: postgres:16
restart: always
shm_size: 128mb
environment:
- POSTGRES_PASSWORD
ports:
- 5432:5432
healthcheck:
test: [ "CMD-SHELL", "pg_isready -U postgres" ]
interval: 5s
timeout: 5s
retries: 5
volumes:
- ./volumes/pgdata:/var/lib/postgresql/data

nginx:
container_name: nginx
image: nginx:latest
ports:
- "80:80"
- "443:443"
volumes:
- ./volumes/nginx.conf:/etc/nginx/nginx.conf:ro
depends_on:
- template
- notes
- stackoverflow
- large-file-upload

networks:
default:
driver: bridge

0 comments on commit c2295ec

Please sign in to comment.