Compare commits
3 Commits
8e2cd7f9a1
...
master
Author | SHA1 | Date | |
---|---|---|---|
36356093ff | |||
03e9317041 | |||
b6c684cdd1 |
49
examples/devcontainers/README.md
Normal file
@ -0,0 +1,49 @@
|
||||
# Overview
|
||||
This is a practical example of a "basic" fullstack application. This application has been fully containerized to be run locally in development mode as well as for deployment to production. It is composed of the following services:
|
||||
|
||||
- frontend - Basic React app bootstrapped with `yarn create vite`
|
||||
- backend - AdonisJS API Backend [https://adonisjs.com]()
|
||||
- database - Postgres database
|
||||
- reverse_proxy - Traefik ingress controller handling reverse proxy for the frontend and backend applications.
|
||||
|
||||
## Getting Started
|
||||
|
||||
### Devcontainer
|
||||
You can run this project via dev containers. First you will need to ensure that you have the [VSCode dev containers extension](https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-containers)
|
||||
|
||||
Once you have the extension installed, there are a couple ways to get started. From this directory run `code .` to open a new VSCode window targeting this directory. After a few seconds you should get a notification in the bottom right asking if you want to reopen the workspace in a container. This will open a new VScode window and will start the process of building and running all of the containers.
|
||||
<video src="./open-devcontainers-option1.m4v" controls></video>
|
||||
|
||||
Another method is to open the `Command Palette` (CMD+Shift+P) and search for `Dev Containers: Open Folder in Dev Container`. Select this folder and VScode will open a new window and kick off the process. The very first time you do this it will take several minutes to build the images and start the containers.
|
||||
|
||||
<video src="./open-devcontainers-option2.m4v" controls></video>
|
||||
Alternatively, you can also just use the compose files to start a stack and connect your VSCode instance to the backend container.
|
||||
|
||||
To do that, clone the repo and `cd` into this directory.
|
||||
|
||||
```shell
|
||||
cd examples/devcontainers
|
||||
docker compose up
|
||||
```
|
||||
|
||||
The first time you run `docker compose up` it may take a few minutes as Docker will need to build images for the frontend and backend. Also there are some database migrations and seed data that need to happen. Those are handled by `backend/entrypoint.sh`. This is handled for you automatically since it is baked into the image. Once everything is up you should be able to access the frontend at [http://app.docker.localhost:8888]() and the backend at [http://app.docker.localhost:8888/api]()
|
||||
|
||||

|
||||
|
||||
|
||||
## Developing
|
||||
When running the `compose` stack, the backend/frontend node_modules are isolated from your host system. This is common in dev environment setups. In this case it is advised to use a Dev container. The following video demonstrates starting a dev container by using the VSCode plugin.
|
||||
|
||||
<video src="../../assets/open-dev-container.m4v" controls></video>
|
||||
|
||||
### Proxying and routes
|
||||
You will notice that the backend is listening on `http://0.0.0.0:3333/` but the frontend is making requests to `/api/`. This is designed to mimic how you would deploy something like this in production where the backend would be behind a reverse proxy. Traefik has some really nice middleware that allows us to easily tell it to route requests destined for `/api` to `/`. The bit that handles that are these labels:
|
||||
|
||||
```compose
|
||||
labels:
|
||||
- "traefik.http.middlewares.strip-api-prefix.stripprefix.prefixes=/api"
|
||||
- "traefik.http.routers.backend.rule=Host(`app.docker.localhost`) && PathPrefix(`/api`)"
|
||||
- "traefik.http.routers.backend.middlewares=strip-api-prefix@docker"
|
||||
```
|
||||
|
||||
We are defining a middleware named `strip-api-prefix` using the built in `strippreffix` Traefik middleware. We are then telling it to remove `/api` from any requests it handles. We then attach that to our backend router.
|
@ -12,11 +12,6 @@ ADD package.json package-lock.json ./
|
||||
RUN npm ci
|
||||
|
||||
FROM deps AS develop
|
||||
WORKDIR /app/backend
|
||||
COPY dev-entrypoint.sh /entrypoint.sh
|
||||
COPY .env.example /app/backend/.env
|
||||
RUN chmod +x /entrypoint.sh
|
||||
ENV NODE_ENV=development
|
||||
WORKDIR /app
|
||||
COPY entrypoint.sh /entrypoint.sh
|
||||
RUN chmod +x /entrypoint.sh
|
@ -1,6 +1,7 @@
|
||||
#!/bin/sh
|
||||
|
||||
cd /app/backend
|
||||
cp .env.example .env
|
||||
echo "starting up..."
|
||||
node ace generate:key
|
||||
|
@ -27,8 +27,6 @@ services:
|
||||
- "traefik.http.middlewares.strip-api-prefix.stripprefix.prefixes=/api"
|
||||
- "traefik.http.routers.backend.rule=Host(`app.docker.localhost`) && PathPrefix(`/api`)"
|
||||
- "traefik.http.routers.backend.middlewares=strip-api-prefix@docker"
|
||||
env_file:
|
||||
- ./backend/.env
|
||||
depends_on:
|
||||
db:
|
||||
condition: service_healthy
|
Before Width: | Height: | Size: 1.5 KiB After Width: | Height: | Size: 1.5 KiB |
Before Width: | Height: | Size: 6.6 KiB After Width: | Height: | Size: 6.6 KiB |
Before Width: | Height: | Size: 4.0 KiB After Width: | Height: | Size: 4.0 KiB |
Before Width: | Height: | Size: 170 KiB After Width: | Height: | Size: 170 KiB |
BIN
examples/devcontainers/open-devcontainers-option1.m4v
Normal file
BIN
examples/devcontainers/open-devcontainers-option2.m4v
Normal file
@ -1,37 +0,0 @@
|
||||
# Overview
|
||||
This is a practical example of a "basic" fullstack application. This application has been fully containerized to be run locally in development mode as well as for deployment to production. It is composed of the following services:
|
||||
|
||||
- frontend - Basic React app bootstrapped with `yarn create vite`
|
||||
- backend - AdonisJS API Backend [https://adonisjs.com]()
|
||||
- database - Postgres database
|
||||
- reverse_proxy - Traefik ingress controller handling reverse proxy for the frontend and backend applications.
|
||||
|
||||
## Getting Started
|
||||
Clone the repo and `cd` into the `compose` directory.
|
||||
|
||||
```shell
|
||||
cp backend/.env.example backend/.env
|
||||
docker compose up
|
||||
```
|
||||
|
||||
The first time you run `docker compose up` it may take a few minutes as Docker will need to build images for the frontend and backend. Also there are some database migrations and seed data that need to happen. Those are handled by `backend/dev-entrypoint.sh`. This is handled for you automatically since it is baked into the image. Once everything is up you should be able to access the frontend at [http://app.docker.localhost:8888]() and the backend at [http://app.docker.localhost:8888/api]()
|
||||
|
||||

|
||||
|
||||
|
||||
## Developing
|
||||
When running the `compose` stack, the backend node_modules are isolated from your host system. This is common in dev environment setups. In this case it is advised to use a Dev container. The following video demonstrates starting a dev container by using the VSCode plugin.
|
||||
|
||||
<video src="../../assets/open-dev-container.m4v" controls></video>
|
||||
|
||||
### Proxying and routes
|
||||
You will notice that the backend is listening on `http://0.0.0.0:3333/` but the frontend is making requests to `/api/`. This is designed to mimic how you would deploy something like this in production where the backend would be behind a reverse proxy. Traefik has some really nice middleware that allows us to easily tell it to route requests destined for `/api` to `/`. The bit that handles that are these labels:
|
||||
|
||||
```compose
|
||||
labels:
|
||||
- "traefik.http.middlewares.strip-api-prefix.stripprefix.prefixes=/api"
|
||||
- "traefik.http.routers.backend.rule=Host(`app.docker.localhost`) && PathPrefix(`/api`)"
|
||||
- "traefik.http.routers.backend.middlewares=strip-api-prefix@docker"
|
||||
```
|
||||
|
||||
We are defining a middleware named `strip-api-prefix` using the built in `strippreffix` Traefik middleware. We are then telling it to remove `/api` from any requests it handles. We then attach that to our backend router.
|