Skip to content

Commit 768906b

Browse files
Add deployment docker compose to VPS (#1)
1 parent f62cec7 commit 768906b

File tree

8 files changed

+122
-70
lines changed

8 files changed

+122
-70
lines changed

.github/workflows/deploy-to-digital-ocean.yml

Lines changed: 0 additions & 32 deletions
This file was deleted.

.github/workflows/on-release-tag.yml

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -99,14 +99,3 @@ jobs:
9999
docker push ghcr.io/hackyourfuture/course-hub-frontend:${{ steps.get-version.outputs.version }}
100100
docker push ghcr.io/hackyourfuture/course-hub-frontend:latest
101101
fi
102-
103-
deploy:
104-
# do not execute on forks
105-
if: ${{ github.repository == 'HackYourFuture/CourseHub' && (github.event_name == 'push' || inputs.deploy) }}
106-
needs: [build-course-hub-backend, build-course-hub-frontend]
107-
permissions:
108-
contents: read
109-
uses: ./.github/workflows/deploy-to-digital-ocean.yml
110-
secrets: inherit
111-
with:
112-
version: ${{ needs.build-course-hub-backend.outputs.version }}

README.md

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,14 @@ docker compose up -d
3838

3939
To run the backend application, you can either:
4040

41-
* From the `backend` directory, run `./gradlew bootRun` in the terminal to us Gradle CLI
41+
* Start application from the terminal:
42+
```bash
43+
cd backend
44+
./gradlew bootRun
45+
```
4246
* Run the `CourseHubApplication` main class from your IDE.
4347

44-
Now you can access the CourseHub frontend UI on `http://localhost:80` and the backend API on `http://localhost:8080`.
48+
Now you can access the CourseHub frontend UI on `http://localhost:3000` and the backend API on `http://localhost:8080`.
4549

4650
### Making requests
4751

@@ -55,35 +59,35 @@ You can also see all available endpoints in the [OpenAPI documentation](http://l
5559

5660
### Running the frontend
5761

58-
By default, the frontend will be running on `http://localhost:80` from Docker compose. If you want to run it
62+
By default, the frontend will be running on `http://localhost:3000` from Docker compose. If you want to run it
5963
locally, follow the steps below.
6064

6165
To install the required dependencies (only once), from the `frontend` directory, run:
62-
63-
```bash
66+
```bash
67+
cd frontend
6468
npm install
6569
```
6670

6771
To run the frontend application locally, from the `frontend` directory, run:
68-
6972
```bash
73+
cd frontend
7074
npm run dev
7175
```
7276

7377
Now you can access the CourseHub frontend UI on `http://localhost:5173` in development mode.
7478

7579
### Building docker images
7680

77-
To build a Docker image of the course-hub backend, run the following command:
78-
81+
To build a Docker image of the course-hub backend, from the `backend` directory, run:
7982
```bash
83+
cd backend
8084
./gradlew bootBuildImage
8185
```
8286

8387
To build a Docker image for the frontend, from the `frontend` directory, run:
84-
8588
```bash
86-
docker build -t ghcr.io/hackyourfuture/course-hub-frontend frontend
89+
cd frontend
90+
docker build -t ghcr.io/hackyourfuture/course-hub-frontend .
8791
```
8892

8993
#### Running docker image
@@ -92,7 +96,7 @@ After the image is built, you can run it using a special Docker Compose profile
9296
you're running it from Gradle or IDE)_:
9397

9498
```bash
95-
docker compose --profile include-course-hub up
99+
docker compose up -d
96100
```
97101

98102
### Cleanup
@@ -101,5 +105,5 @@ Keep in mind that containers will keep running in the background even after you
101105
the containers, run:
102106

103107
```bash
104-
docker compose --profile include-course-hub down -v
108+
docker compose down -v
105109
```

deployment/README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
## Deployment
2+
3+
This directory contains Docker Compose configuration to deploy everything on a single VPS.
4+
5+
If the only updates are the image versions, then `watchtower` will take care of updating. Otherwise, first sync the deployment:
6+
```bash
7+
scp -r . user@server:/opt/course-hub/
8+
```
9+
then restart docker containers using SSH:
10+
```bash
11+
ssh user@server
12+
cd /opt/course-hub
13+
docker compose down
14+
docker compose up -d
15+
```

deployment/docker-compose.yaml

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
services:
2+
# Nginx is responsible for global routing
3+
# /api -> course-hub-backend
4+
# / -> course-hub-frontend
5+
nginx:
6+
image: nginx:latest
7+
container_name: nginx
8+
ports:
9+
- "443:443"
10+
- "80:80"
11+
volumes:
12+
- ./nginx.conf:/etc/nginx/conf.d/default.conf
13+
- ./certificates:/etc/nginx/certificates
14+
# Postgres, main data store used by course-hub-backend
15+
postgres:
16+
image: postgres:18
17+
container_name: postgres
18+
environment:
19+
POSTGRES_USER: course_user
20+
POSTGRES_PASSWORD: course_user_password
21+
POSTGRES_DB: coursehub
22+
volumes:
23+
- postgres:/var/lib/postgresql
24+
ports:
25+
- "5432:5432"
26+
# Redis, auth session storage used by course-hub-backend
27+
redis:
28+
image: redis:7
29+
container_name: redis
30+
volumes:
31+
- redis:/data
32+
ports:
33+
- "6379:6379"
34+
course-hub-frontend:
35+
image: ghcr.io/hackyourfuture/course-hub-frontend:latest
36+
container_name: course-hub-frontend
37+
environment:
38+
BACKEND_URL: http://localhost/api
39+
ports:
40+
- "3000:3000"
41+
course-hub-backend:
42+
image: ghcr.io/hackyourfuture/course-hub-backend:latest
43+
container_name: course-hub-backend
44+
environment:
45+
JVM_TOOL_OPTS: -XX:ReservedCodeCacheSize=80M
46+
BPL_JVM_THREAD_COUNT: 20
47+
SPRING_DATASOURCE_URL: jdbc:postgresql://postgres:5432/coursehub
48+
SPRING_DATA_REDIS_HOST: redis
49+
depends_on:
50+
postgres:
51+
condition: service_started
52+
redis:
53+
condition: service_started
54+
ports:
55+
- "8080:8080"
56+
# Agent that monitors whenever new versions of images are published and recreates the containers
57+
watchtower:
58+
image: containrrr/watchtower
59+
volumes:
60+
- /var/run/docker.sock:/var/run/docker.sock
61+
command: --interval 30
62+
63+
volumes:
64+
postgres:
65+
redis:

deployment/nginx.conf

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
server {
2+
listen 80;
3+
server_name _;
4+
5+
6+
location /api {
7+
rewrite ^/api(/.*)$ $1 break;
8+
proxy_pass http://course-hub-backend:8080;
9+
proxy_set_header Host $host;
10+
proxy_set_header X-Real-IP $remote_addr;
11+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
12+
proxy_set_header X-Forwarded-Proto $scheme;
13+
}
14+
15+
location / {
16+
proxy_pass http://course-hub-frontend:3000;
17+
proxy_set_header Host $host;
18+
proxy_set_header X-Real-IP $remote_addr;
19+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
20+
proxy_set_header X-Forwarded-Proto $scheme;
21+
}
22+
}
23+

docker-compose.yaml

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
services:
22
postgres:
3-
image: postgres:17
3+
image: postgres:18
44
container_name: postgres
55
environment:
66
POSTGRES_USER: course_user
@@ -19,17 +19,5 @@ services:
1919
environment:
2020
BACKEND_URL: http://localhost:8080
2121
ports:
22-
- "80:80"
23-
course-hub-backend:
24-
image: ghcr.io/hackyourfuture/course-hub-backend:latest
25-
container_name: course-hub
26-
profiles:
27-
- include-course-hub
28-
environment:
29-
SPRING_DATASOURCE_URL: jdbc:postgresql://postgres:5432/coursehub
30-
depends_on:
31-
postgres:
32-
condition: service_started
33-
ports:
34-
- "8080:8080"
22+
- "3000:3000"
3523

frontend/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,5 @@ COPY public/images /usr/share/nginx/html/images
1313
COPY nginx.conf /etc/nginx/conf.d/default.conf
1414
COPY nginx-entrypoint.sh /usr/local/bin/nginx-entrypoint.sh
1515

16-
EXPOSE 80
16+
EXPOSE 3000
1717
CMD ["nginx-entrypoint.sh"]

0 commit comments

Comments
 (0)