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

Closes #67 Hot-reload the code in the containers #69

Merged
merged 4 commits into from
Sep 23, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
16 changes: 14 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,30 @@ dotnet dev-certs https -ep .aspnet/https/aspnetapp.pfx -p devcertpasswd --trust
```

Next go to the `scripts` directory and run `apply_migrations.ps1`
Next You should go back to the main directory and run `docker compose up --build`
Next You should go back to the main directory and run `docker compose up --build --watch`
This can be done with the following snippet.

```powershell
cd scripts
.\apply_migrations.ps1
cd ..\
docker compose up --build
docker compose up --build --watch
```

You can now visit the site at: <http://localhost:8888/>

## Scripts

Directory `scripts` contains some helpful scripts which automate some parts of working with this directory.

## Development

The application is started using the following command:

```bash
docker compose up --build --watch
```

The `--watch` parameter starts containers with the `hot-reload` feature. This enables the auto-reload functionality, meaning that the container will be automatically reloaded when the code for either the frontend or backend changes.

> The `hot-reload` feature for backend applications uses `dotnet watch`, which only detects changes to existing files. It will not restart the container if new files are added (dotnet watch [issue](https://github.com/dotnet/aspnetcore/issues/8321)).
5 changes: 5 additions & 0 deletions backend/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ WORKDIR /app
EXPOSE 80
EXPOSE 443

FROM mcr.microsoft.com/dotnet/sdk:8.0 AS development
COPY . /src
WORKDIR /src
CMD ["dotnet", "watch", "--verbose", "--non-interactive", "--no-launch-profile", "--project", "src/api/"]

#Todo: clean it up for multiproject build
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
WORKDIR /src
Expand Down
20 changes: 18 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,26 @@
version: "3.9"
services:
frontend:
container_name: ks-frontend
build:
context: ./frontend
command: ["npm", "run", "dev"]
ports:
Sojusan marked this conversation as resolved.
Show resolved Hide resolved
- "8888:8888"
develop:
watch:
- action: sync
path: ./frontend
target: /src
ignore:
- node_modules
- action: rebuild
path: package.json

backend:
container_name: ks-backend
build:
context: ./backend
target: development
ports:
- "5001:80"
- "5000:443"
Expand All @@ -20,11 +30,17 @@ services:
ASPNETCORE_Kestrel__Certificates__Default__Path: "/https/aspnetapp.pfx"
ASPNETCORE_Kestrel__Certificates__Default__Password: "devcertpasswd"
ASPNETCORE_URLS: "https://+:443;http://+:80"
DOTNET_USE_POLLING_FILE_WATCHER: true # dotnet watch uses a a polling file watcher. Required for running it in docker.
volumes:
- .aspnet/https:/https/
- .aspnet/https:/https/:ro # read-only on the container
depends_on:
db:
condition: service_healthy
develop:
watch:
- action: sync
path: ./backend
target: /src

db:
image: postgres:14.0-alpine
Expand Down
2 changes: 1 addition & 1 deletion frontend/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
FROM node:current-alpine
WORKDIR /src
COPY package.json .
COPY package*.json .
RUN npm install
COPY . .
RUN npm run build
Expand Down
Loading
Loading