Skip to content

Commit 31831ba

Browse files
Init deployment
1 parent cdcbca1 commit 31831ba

21 files changed

+2967
-4080
lines changed

.github/.keep

Whitespace-only changes.

.github/dependabot.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# To get started with Dependabot version updates, you'll need to specify which
2+
# package ecosystems to update and where the package manifests are located.
3+
# Please see the documentation for all configuration options:
4+
# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates
5+
6+
version: 2
7+
updates:
8+
- package-ecosystem: "npm"
9+
directory: "/frontend"
10+
schedule:
11+
interval: "daily"
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
name: Build and Lint frontend
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
pull_request:
8+
9+
jobs:
10+
lint:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v2
14+
- uses: actions/setup-node@v2
15+
- run: yarn install
16+
working-directory: frontend
17+
- run: yarn build
18+
working-directory: frontend
19+
- run: yarn lint
20+
working-directory: frontend
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
name: Build Docker Images
2+
3+
on:
4+
workflow_dispatch:
5+
push:
6+
branches:
7+
- master
8+
9+
env:
10+
FRONTEND_IMAGE_NAME: peerprep-frontend
11+
NGINX_IMAGE_NAME: peerprep-nginx
12+
13+
jobs:
14+
build-frontend-image:
15+
runs-on: ubuntu-latest
16+
permissions:
17+
contents: read
18+
packages: write
19+
steps:
20+
- name: Check out Source
21+
uses: actions/checkout@v2
22+
- name: Log in to the Container Registry
23+
uses: docker/login-action@v1
24+
with:
25+
registry: ghcr.io
26+
username: ay2324s1-course-assessment-g21
27+
password: ${{ secrets.GITHUB_TOKEN }}
28+
- name: Build and Push Docker Image
29+
uses: docker/build-push-action@v2
30+
with:
31+
context: .
32+
file: deployment/Dockerfile-frontend
33+
push: true
34+
tags: ghcr.io/ay2324s1-course-assessment-g21/${{ env.FRONTEND_IMAGE_NAME }}:latest
35+
36+
build-nginx-image:
37+
runs-on: ubuntu-latest
38+
permissions:
39+
contents: read
40+
packages: write
41+
steps:
42+
- name: Check out Source
43+
uses: actions/checkout@v2
44+
- name: Log in to the Container Registry
45+
uses: docker/login-action@v1
46+
with:
47+
registry: ghcr.io
48+
username: ay2324s1-course-assessment-g21
49+
password: ${{ secrets.GITHUB_TOKEN }}
50+
- name: Build and Push Docker Image
51+
uses: docker/build-push-action@v2
52+
with:
53+
context: .
54+
file: deployment/Dockerfile-nginx
55+
push: true
56+
tags: ghcr.io/ay2324s1-course-assessment-g21/${{ env.NGINX_IMAGE_NAME }}:latest

deployment/Dockerfile-frontend

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# To build a Docker image from this file, run from the root directory:
2+
# docker build -f deployment/Dockerfile-frontend -t giving-coupons-frontend .
3+
4+
# Intermediate image for building the Next app
5+
FROM node:16.13.0
6+
7+
# Environment variables
8+
ENV APP_ROOT /frontend
9+
10+
# Copy source code into container
11+
RUN mkdir --parents $APP_ROOT
12+
WORKDIR $APP_ROOT
13+
COPY frontend .
14+
15+
# Install dependencies
16+
RUN yarn install --frozen-lockfile
17+
18+
# Build app
19+
RUN yarn build
20+
21+
# Expose port
22+
EXPOSE 3000
23+
24+
# Final image for running the Next app
25+
CMD ["yarn", "start"]

deployment/Dockerfile-nginx

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Use nginx to serve the app
2+
FROM nginx:stable
3+
4+
# Delete NGINX defaults
5+
RUN rm -f /etc/nginx/conf.d/* /etc/nginx/sites-enabled/*
6+
7+
# Copy NGINX config
8+
COPY deployment/nginx/nginx.conf /etc/nginx
9+
COPY deployment/nginx/sites-enabled/* /etc/nginx/sites-enabled/
10+
11+
# Expose ports
12+
EXPOSE 80
13+
EXPOSE 443
14+
15+
# Add a script containing the main command to be executed
16+
COPY deployment/scripts/cmd-frontend.sh /usr/bin/
17+
CMD ["cmd-nginx.sh"]

deployment/docker-compose.yml

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
version: "3.8"
2+
3+
services:
4+
frontend:
5+
image: ghcr.io/ay2324s1-course-assessment-g21/peerprep-frontend:latest
6+
container_name: peerprep-frontend
7+
restart: always
8+
depends_on:
9+
- backend
10+
networks:
11+
- peerprep-network
12+
logging:
13+
driver: journald
14+
expose:
15+
- "3000"
16+
17+
nginx:
18+
image: ghcr.io/ay2324s1-course-assessment-g21/peerprep-nginx:latest
19+
container_name: peerprep-nginx
20+
restart: always
21+
volumes:
22+
- /etc/letsencrypt:/etc/letsencrypt
23+
- /var/www/certbot:/var/www/certbot
24+
depends_on:
25+
- frontend
26+
networks:
27+
- peerprep-network
28+
logging:
29+
driver: journald
30+
ports:
31+
- "80:80"
32+
- "443:443"
33+
34+
certbot:
35+
image: certbot/certbot
36+
container_name: peerprep-certbot
37+
restart: always
38+
volumes:
39+
- /etc/letsencrypt:/etc/letsencrypt
40+
- /var/www/certbot:/var/www/certbot
41+
depends_on:
42+
- nginx
43+
networks:
44+
- peerprep-network
45+
entrypoint: "/bin/sh -c 'trap exit TERM; while :; do certbot renew; sleep 12h & wait $${!}; done;'"
46+
47+
networks:
48+
peerprep-network:

deployment/nginx/nginx.conf

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
user nginx;
2+
worker_processes auto;
3+
error_log /var/log/nginx/error.log warn;
4+
pid /var/run/nginx.pid;
5+
6+
events {
7+
worker_connections 1024;
8+
}
9+
10+
http {
11+
include /etc/nginx/mime.types;
12+
default_type application/octet-stream;
13+
14+
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
15+
'$status $body_bytes_sent "$http_referer" '
16+
'"$http_user_agent" "$http_x_forwarded_for"';
17+
18+
access_log /var/log/nginx/access.log main;
19+
20+
sendfile on;
21+
tcp_nopush on;
22+
tcp_nodelay on;
23+
keepalive_timeout 65;
24+
types_hash_max_size 2048;
25+
26+
gzip on;
27+
gzip_disable "msie6";
28+
gzip_vary on;
29+
gzip_proxied any;
30+
gzip_comp_level 6;
31+
gzip_buffers 16 8k;
32+
gzip_http_version 1.1;
33+
gzip_min_length 256;
34+
gzip_types
35+
application/atom+xml
36+
application/geo+json
37+
application/javascript
38+
application/x-javascript
39+
application/json
40+
application/ld+json
41+
application/manifest+json
42+
application/rdf+xml
43+
application/rss+xml
44+
application/xhtml+xml
45+
application/xml
46+
font/eot
47+
font/otf
48+
font/ttf
49+
image/svg+xml
50+
text/css
51+
text/javascript
52+
text/plain
53+
text/xml;
54+
55+
include /etc/nginx/conf.d/*.conf;
56+
include /etc/nginx/sites-enabled/*;
57+
}

deployment/scripts/cmd-nginx.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/bin/sh
2+
3+
while :; do
4+
# Run the following commands every 6 hours
5+
sleep 6h & wait ${!};
6+
# Reload NGINX so that it serves the latest certificates
7+
nginx -s reload;
8+
done &
9+
# Run NGINX in foreground so that Docker can track it properly
10+
nginx -g "daemon off;"

frontend/.eslintignore

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
*.md
2+
*.lock
3+
*.log
4+
*.scss
5+
*.css
6+
public/**
7+
.next/
8+
out/
9+
*.ico

0 commit comments

Comments
 (0)