Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deploy cms to staging docker in aws - add nginx reverse proxy #47

Merged
merged 5 commits into from
Jan 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,7 @@ indent_size = 2
# for markdown files
[*.md]
trim_trailing_whitespace = false

# for nginx.conf
[nginx.conf]
indent_size = 4
29 changes: 27 additions & 2 deletions .github/workflows/cd-staging.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
name: Build CMS Docker Image
runs-on: ubuntu-22.04
steps:
- name: checkout repo
- name: Checkout repo
uses: actions/checkout@v3

- name: Login to GitHub Container Registry
Expand All @@ -30,11 +30,36 @@ jobs:
ghcr.io/${{ github.repository_owner }}/website/cms:${{ github.sha }}
ghcr.io/${{ github.repository_owner }}/website/cms:latest

build-nginx-staging:
name: Build nginx Staging Image
runs-on: ubuntu-22.04
steps:
- name: Checkout repo
uses: actions/checkout@v3

- name: Login to GitHub Container Registry
uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build and push
uses: docker/build-push-action@v2
with:
file: ./deployments/staging/nginx/Dockerfile
context: ./deployments/staging/nginx
push: true
tags: |
ghcr.io/${{ github.repository_owner }}/website/nginx-staging:${{ github.sha }}
ghcr.io/${{ github.repository_owner }}/website/nginx-staging:latest

deploy-to-staging:
name: Deploy To Staging
runs-on: ubuntu-22.04
needs: build-cms
needs:
- build-cms
- build-nginx-staging
steps:
- name: Deploy and run docker images
env:
Expand Down
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# data

**/data

# dependencies
node_modules
.pnp
Expand Down Expand Up @@ -34,3 +38,6 @@ yarn-error.log*

# jetbrains
.idea

# env vars
**/.env
3 changes: 2 additions & 1 deletion apps/cms/.env.example
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
MONGODB_URI=
MONGODB_URI=mongodb://localhost/cms
PAYLOAD_SECRET=
PAYLOAD_PUBLIC_SERVER_URL=http://localhost:3000
2 changes: 1 addition & 1 deletion apps/cms/docker/staging/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ services:
context: ../../../../
dockerfile: ./apps/cms/docker/staging/Dockerfile
ports:
- "3000:3000"
- "80:80"

7 changes: 6 additions & 1 deletion apps/cms/src/payload.config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { buildConfig } from 'payload/config';
import path from 'path';
import dotenv from 'dotenv';

import Categories from './collections/Categories';
import Posts from './collections/Posts';
Expand All @@ -14,8 +15,12 @@ import MerchProducts from "./admin/views/MerchProducts";
import { SCSEIcon, SCSELogo } from "./admin/graphics/Logos";
import BeforeNavLinks from "./admin/components/BeforeNavLinks";

dotenv.config({
path: path.resolve(__dirname, '../.env'),
});

export default buildConfig({
serverURL: 'http://localhost:3000',
serverURL: process.env.PAYLOAD_PUBLIC_SERVER_URL,
admin: {
components: {
graphics: {
Expand Down
1 change: 1 addition & 0 deletions deployments/staging/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
COMPOSE_PROJECT_NAME=ntuscse-website-staging
1 change: 1 addition & 0 deletions deployments/staging/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
COMPOSE_PROJECT_NAME=ntuscse-website-staging
5 changes: 5 additions & 0 deletions deployments/staging/cms.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
MONGODB_URI=mongodb://ntuscse-website-staging-mongo-1/cms:27017
PAYLOAD_SECRET=f5d5a7127f845b8f4d7c917
PAYLOAD_CONFIG_PATH=src/payload.config.ts
PAYLOAD_PUBLIC_SERVER_URL=http://localhost

1 change: 1 addition & 0 deletions deployments/staging/cms.env.example
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
PAYLOAD_SECRET=
MONGODB_URI=
PAYLOAD_CONFIG_PATH=
28 changes: 24 additions & 4 deletions deployments/staging/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,22 +1,42 @@

services:
cms:
image: ghcr.io/ntuscse/website/cms
networks:
- cms-network
ports:
- 80:3000
- "7001:80"
env_file:
- cms.env
restart: always
depends_on:
- mongo

mongo:
image: mongo:latest
networks:
- cms-network
ports:
- "27017:27017"
command:
- --storageEngine=wiredTiger
volumes:
- ./data:/data/db
logging:
driver: none
restart: always

nginx:
# image: ghcr.io/ntuscse/website/nginx-staging
build: ./nginx
networks:
- cms-network
ports:
- "80:80"
- "443:443"
depends_on:
- cms

networks:
cms-network:
driver: bridge

volumes:
data:
3 changes: 3 additions & 0 deletions deployments/staging/nginx/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
FROM nginx
RUN rm /etc/nginx/conf.d/default.conf
COPY nginx.conf /etc/nginx/conf.d/default.conf
51 changes: 51 additions & 0 deletions deployments/staging/nginx/nginx.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
server {
listen 80;
listen [::]:80;
server_name localhost;

# client_max_body_size 30M;

location /admin {
proxy_pass http://payload-cms:5000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
proxy_set_header X-Forwarded-For $remote_addr;
}

location /api {
proxy_pass http://payload-cms:5000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
proxy_set_header X-Forwarded-For $remote_addr;
}

error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}

# location /admin {
# proxy_pass http://cms:3000/admin;
# proxy_set_header Host $host;
# proxy_set_header X-Real-IP $remote_addr;
# # proxy_redirect off;
# # proxy_buffering off;
# # proxy_request_buffering off;
# # proxy_http_version 1.1;
# # proxy_set_header Upgrade $http_upgrade;
# # proxy_set_header Connection "upgrade";
# }
#
# location /api {
# proxy_pass http://cms:3000/api;
# proxy_set_header Host $host;
# proxy_set_header X-Real-IP $remote_addr;
# proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
# }
}
7 changes: 4 additions & 3 deletions turbo.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,20 @@
"pipeline": {
"dev": {
"cache": false,
"env": ["PAYLOAD_SECRET", "MONGODB_URI", "WORDPRESS_API_URL"]
"env": ["PAYLOAD_SECRET", "MONGODB_URI", "WORDPRESS_API_URL", "PAYLOAD_PUBLIC_SERVER_URL"]
},
"build": {
"dependsOn": ["^build"],
"env": ["PAYLOAD_SECRET", "MONGODB_URI", "WORDPRESS_API_URL"],
"env": ["PAYLOAD_SECRET", "MONGODB_URI", "WORDPRESS_API_URL", "PAYLOAD_PUBLIC_SERVER_URL"],
"outputs": ["dist/**", ".next/**"]
},
"build-storybook": {
"dependsOn": ["^build"],
"outputs": ["storybook-static"]
},
"start": {
"dependsOn": ["build"]
"dependsOn": ["build"],
"env": ["PAYLOAD_SECRET", "MONGODB_URI", "WORDPRESS_API_URL", "PAYLOAD_PUBLIC_SERVER_URL"]
},
"lint": {
"outputs": []
Expand Down