Skip to content
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
32 changes: 0 additions & 32 deletions .github/workflows/deploy-to-digital-ocean.yml

This file was deleted.

11 changes: 0 additions & 11 deletions .github/workflows/on-release-tag.yml
Original file line number Diff line number Diff line change
Expand Up @@ -99,14 +99,3 @@ jobs:
docker push ghcr.io/hackyourfuture/course-hub-frontend:${{ steps.get-version.outputs.version }}
docker push ghcr.io/hackyourfuture/course-hub-frontend:latest
fi

deploy:
# do not execute on forks
if: ${{ github.repository == 'HackYourFuture/CourseHub' && (github.event_name == 'push' || inputs.deploy) }}
needs: [build-course-hub-backend, build-course-hub-frontend]
permissions:
contents: read
uses: ./.github/workflows/deploy-to-digital-ocean.yml
secrets: inherit
with:
version: ${{ needs.build-course-hub-backend.outputs.version }}
28 changes: 16 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,14 @@ docker compose up -d

To run the backend application, you can either:

* From the `backend` directory, run `./gradlew bootRun` in the terminal to us Gradle CLI
* Start application from the terminal:
```bash
cd backend
./gradlew bootRun
```
* Run the `CourseHubApplication` main class from your IDE.

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

### Making requests

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

### Running the frontend

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

To install the required dependencies (only once), from the `frontend` directory, run:

```bash
```bash
cd frontend
npm install
```

To run the frontend application locally, from the `frontend` directory, run:

```bash
cd frontend
npm run dev
```

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

### Building docker images

To build a Docker image of the course-hub backend, run the following command:

To build a Docker image of the course-hub backend, from the `backend` directory, run:
```bash
cd backend
./gradlew bootBuildImage
```

To build a Docker image for the frontend, from the `frontend` directory, run:

```bash
docker build -t ghcr.io/hackyourfuture/course-hub-frontend frontend
cd frontend
docker build -t ghcr.io/hackyourfuture/course-hub-frontend .
```

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

```bash
docker compose --profile include-course-hub up
docker compose up -d
```

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

```bash
docker compose --profile include-course-hub down -v
docker compose down -v
```
15 changes: 15 additions & 0 deletions deployment/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
## Deployment

This directory contains Docker Compose configuration to deploy everything on a single VPS.

If the only updates are the image versions, then `watchtower` will take care of updating. Otherwise, first sync the deployment:
```bash
scp -r . user@server:/opt/course-hub/
```
then restart docker containers using SSH:
```bash
ssh user@server
cd /opt/course-hub
docker compose down
docker compose up -d
```
65 changes: 65 additions & 0 deletions deployment/docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
services:
# Nginx is responsible for global routing
# /api -> course-hub-backend
# / -> course-hub-frontend
nginx:
image: nginx:latest
container_name: nginx
ports:
- "443:443"
- "80:80"
volumes:
- ./nginx.conf:/etc/nginx/conf.d/default.conf
- ./certificates:/etc/nginx/certificates
# Postgres, main data store used by course-hub-backend
postgres:
image: postgres:18
container_name: postgres
environment:
POSTGRES_USER: course_user
POSTGRES_PASSWORD: course_user_password
POSTGRES_DB: coursehub
volumes:
- postgres:/var/lib/postgresql
ports:
- "5432:5432"
# Redis, auth session storage used by course-hub-backend
redis:
image: redis:7
container_name: redis
volumes:
- redis:/data
ports:
- "6379:6379"
course-hub-frontend:
image: ghcr.io/hackyourfuture/course-hub-frontend:latest
container_name: course-hub-frontend
environment:
BACKEND_URL: http://localhost/api
ports:
- "3000:3000"
course-hub-backend:
image: ghcr.io/hackyourfuture/course-hub-backend:latest
container_name: course-hub-backend
environment:
JVM_TOOL_OPTS: -XX:ReservedCodeCacheSize=80M
BPL_JVM_THREAD_COUNT: 20
SPRING_DATASOURCE_URL: jdbc:postgresql://postgres:5432/coursehub
SPRING_DATA_REDIS_HOST: redis
depends_on:
postgres:
condition: service_started
redis:
condition: service_started
ports:
- "8080:8080"
# Agent that monitors whenever new versions of images are published and recreates the containers
watchtower:
image: containrrr/watchtower
volumes:
- /var/run/docker.sock:/var/run/docker.sock
command: --interval 30

volumes:
postgres:
redis:
23 changes: 23 additions & 0 deletions deployment/nginx.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
server {
listen 80;
server_name _;


location /api {
rewrite ^/api(/.*)$ $1 break;
proxy_pass http://course-hub-backend:8080;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}

location / {
proxy_pass http://course-hub-frontend:3000;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
}

16 changes: 2 additions & 14 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
services:
postgres:
image: postgres:17
image: postgres:18
container_name: postgres
environment:
POSTGRES_USER: course_user
Expand All @@ -19,17 +19,5 @@ services:
environment:
BACKEND_URL: http://localhost:8080
ports:
- "80:80"
course-hub-backend:
image: ghcr.io/hackyourfuture/course-hub-backend:latest
container_name: course-hub
profiles:
- include-course-hub
environment:
SPRING_DATASOURCE_URL: jdbc:postgresql://postgres:5432/coursehub
depends_on:
postgres:
condition: service_started
ports:
- "8080:8080"
- "3000:3000"

2 changes: 1 addition & 1 deletion frontend/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ COPY public/images /usr/share/nginx/html/images
COPY nginx.conf /etc/nginx/conf.d/default.conf
COPY nginx-entrypoint.sh /usr/local/bin/nginx-entrypoint.sh

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