Skip to content

Commit

Permalink
add configuration to use react-rust-postgres sample with Docker Dev E…
Browse files Browse the repository at this point in the history
…nvironments feature (docker#264)

Signed-off-by: Guillaume Lours <[email protected]>
  • Loading branch information
glours authored Jul 8, 2022
1 parent b53e454 commit c781f1c
Show file tree
Hide file tree
Showing 5 changed files with 94 additions and 0 deletions.
51 changes: 51 additions & 0 deletions react-rust-postgres/.docker/docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
name: react-rust-postgres
services:
frontend:
build:
context: ../frontend
target: dev-envs
networks:
- client-side
ports:
- 3000:3000
volumes:
- /var/run/docker.sock:/var/run/docker.sock

backend:
build:
context: ../backend
target: dev-envs
environment:
- RUST_LOG=debug
- PG_DBNAME=postgres
- PG_HOST=db
- PG_USER=postgres
- PG_PASSWORD=mysecretpassword
- ADDRESS=0.0.0.0:8000
networks:
- client-side
- server-side
volumes:
- /var/run/docker.sock:/var/run/docker.sock
depends_on:
- db

db:
image: postgres:12-alpine
restart: always
environment:
- POSTGRES_PASSWORD=mysecretpassword
networks:
- server-side
ports:
- 5432:5432
volumes:
- db-data:/var/lib/postgresql/data

networks:
client-side: {}
server-side: {}

volumes:
backend-cache: {}
db-data: {}
18 changes: 18 additions & 0 deletions react-rust-postgres/backend/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# syntax=docker/dockerfile:1.4
FROM rust:buster AS base

ENV USER=root
Expand All @@ -16,6 +17,23 @@ EXPOSE 8000

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

FROM base AS dev-envs

EXPOSE 8000
RUN <<EOF
apt-get update
apt-get install -y --no-install-recommends git
EOF

RUN <<EOF
useradd -s /bin/bash -m vscode
groupadd docker
usermod -aG docker vscode
EOF
# install Docker tools (cli, buildx, compose)
COPY --from=gloursdocker/docker / /
CMD [ "cargo", "run", "--offline" ]

FROM base AS builder

RUN cargo build --release --offline
Expand Down
1 change: 1 addition & 0 deletions react-rust-postgres/compose.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
name: react-rust-postgres
services:
frontend:
build:
Expand Down
16 changes: 16 additions & 0 deletions react-rust-postgres/frontend/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# syntax=docker/dockerfile:1.4
FROM node:lts AS development

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

CMD [ "npm", "start" ]

FROM development as dev-envs
RUN <<EOF
apt-get update
apt-get install -y --no-install-recommends git
EOF

RUN <<EOF
useradd -s /bin/bash -m vscode
groupadd docker
usermod -aG docker vscode
EOF
# install Docker tools (cli, buildx, compose)
COPY --from=gloursdocker/docker / /
CMD [ "npm", "start" ]

FROM development AS builder

RUN npm run build
Expand Down
8 changes: 8 additions & 0 deletions react-rust-postgres/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,11 @@ Removing react-rust-postgres_frontend_1 ... done
Removing react-rust-postgres_db_1 ... done
Removing network react-rust-postgres_default
```

## Use with Docker Development Environments

You can use this sample with the Dev Environments feature of Docker Desktop.
To develop directly frontend or the backend services inside containers, you just need to use the https git url of the sample:
`https://github.com/docker/awesome-compose/tree/master/react-rust-postgres`

![page](../dev-envs.png)

0 comments on commit c781f1c

Please sign in to comment.