Skip to content

Commit c781f1c

Browse files
authored
add configuration to use react-rust-postgres sample with Docker Dev Environments feature (docker#264)
Signed-off-by: Guillaume Lours <[email protected]>
1 parent b53e454 commit c781f1c

File tree

5 files changed

+94
-0
lines changed

5 files changed

+94
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
name: react-rust-postgres
2+
services:
3+
frontend:
4+
build:
5+
context: ../frontend
6+
target: dev-envs
7+
networks:
8+
- client-side
9+
ports:
10+
- 3000:3000
11+
volumes:
12+
- /var/run/docker.sock:/var/run/docker.sock
13+
14+
backend:
15+
build:
16+
context: ../backend
17+
target: dev-envs
18+
environment:
19+
- RUST_LOG=debug
20+
- PG_DBNAME=postgres
21+
- PG_HOST=db
22+
- PG_USER=postgres
23+
- PG_PASSWORD=mysecretpassword
24+
- ADDRESS=0.0.0.0:8000
25+
networks:
26+
- client-side
27+
- server-side
28+
volumes:
29+
- /var/run/docker.sock:/var/run/docker.sock
30+
depends_on:
31+
- db
32+
33+
db:
34+
image: postgres:12-alpine
35+
restart: always
36+
environment:
37+
- POSTGRES_PASSWORD=mysecretpassword
38+
networks:
39+
- server-side
40+
ports:
41+
- 5432:5432
42+
volumes:
43+
- db-data:/var/lib/postgresql/data
44+
45+
networks:
46+
client-side: {}
47+
server-side: {}
48+
49+
volumes:
50+
backend-cache: {}
51+
db-data: {}

react-rust-postgres/backend/Dockerfile

+18
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# syntax=docker/dockerfile:1.4
12
FROM rust:buster AS base
23

34
ENV USER=root
@@ -16,6 +17,23 @@ EXPOSE 8000
1617

1718
CMD [ "cargo", "run", "--offline" ]
1819

20+
FROM base AS dev-envs
21+
22+
EXPOSE 8000
23+
RUN <<EOF
24+
apt-get update
25+
apt-get install -y --no-install-recommends git
26+
EOF
27+
28+
RUN <<EOF
29+
useradd -s /bin/bash -m vscode
30+
groupadd docker
31+
usermod -aG docker vscode
32+
EOF
33+
# install Docker tools (cli, buildx, compose)
34+
COPY --from=gloursdocker/docker / /
35+
CMD [ "cargo", "run", "--offline" ]
36+
1937
FROM base AS builder
2038

2139
RUN cargo build --release --offline

react-rust-postgres/compose.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
name: react-rust-postgres
12
services:
23
frontend:
34
build:

react-rust-postgres/frontend/Dockerfile

+16
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# syntax=docker/dockerfile:1.4
12
FROM node:lts AS development
23

34
ENV CI=true
@@ -11,6 +12,21 @@ COPY . /code
1112

1213
CMD [ "npm", "start" ]
1314

15+
FROM development as dev-envs
16+
RUN <<EOF
17+
apt-get update
18+
apt-get install -y --no-install-recommends git
19+
EOF
20+
21+
RUN <<EOF
22+
useradd -s /bin/bash -m vscode
23+
groupadd docker
24+
usermod -aG docker vscode
25+
EOF
26+
# install Docker tools (cli, buildx, compose)
27+
COPY --from=gloursdocker/docker / /
28+
CMD [ "npm", "start" ]
29+
1430
FROM development AS builder
1531

1632
RUN npm run build

react-rust-postgres/readme.md

+8
Original file line numberDiff line numberDiff line change
@@ -74,3 +74,11 @@ Removing react-rust-postgres_frontend_1 ... done
7474
Removing react-rust-postgres_db_1 ... done
7575
Removing network react-rust-postgres_default
7676
```
77+
78+
## Use with Docker Development Environments
79+
80+
You can use this sample with the Dev Environments feature of Docker Desktop.
81+
To develop directly frontend or the backend services inside containers, you just need to use the https git url of the sample:
82+
`https://github.com/docker/awesome-compose/tree/master/react-rust-postgres`
83+
84+
![page](../dev-envs.png)

0 commit comments

Comments
 (0)