Skip to content

Commit 377fa12

Browse files
committed
updates/
1 parent 4b84324 commit 377fa12

File tree

14 files changed

+1854
-0
lines changed

14 files changed

+1854
-0
lines changed

Cargo.lock

Lines changed: 1565 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
[package]
2+
name = "react-rust-postgres"
3+
version = "0.1.0"
4+
authors = ["Jérémie Drouet <[email protected]>"]
5+
edition = "2018"
6+
7+
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
8+
9+
[dependencies]
10+
actix-web = "4.0.0-beta.8"
11+
deadpool-postgres = "0.9.0"
12+
env_logger = "^0.8"
13+
log = "^0.4"
14+
serde = "1.0"
15+
serde_json = "1.0"
16+
tokio-postgres = "^0.7"
17+
tokio-postgres-migration = "^0.1"

Dockerfile

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
# syntax=docker/dockerfile:1
2+
3+
# Comments are provided throughout this file to help you get started.
4+
# If you need more help, visit the Dockerfile reference guide at
5+
# https://docs.docker.com/engine/reference/builder/
6+
7+
################################################################################
8+
# Create a stage for building the application.
9+
10+
ARG RUST_VERSION=1.70.0
11+
ARG APP_NAME=react-rust-postgres
12+
FROM rust:${RUST_VERSION}-slim-bullseye AS build
13+
ARG APP_NAME
14+
WORKDIR /app
15+
16+
# Build the application.
17+
# Leverage a cache mount to /usr/local/cargo/registry/
18+
# for downloaded dependencies and a cache mount to /app/target/ for
19+
# compiled dependencies which will speed up subsequent builds.
20+
# Leverage a bind mount to the src directory to avoid having to copy the
21+
# source code into the container. Once built, copy the executable to an
22+
# output directory before the cache mounted /app/target is unmounted.
23+
RUN --mount=type=bind,source=src,target=src \
24+
--mount=type=bind,source=Cargo.toml,target=Cargo.toml \
25+
--mount=type=bind,source=Cargo.lock,target=Cargo.lock \
26+
--mount=type=cache,target=/app/target/ \
27+
--mount=type=cache,target=/usr/local/cargo/registry/ \
28+
--mount=type=bind,source=migrations,target=migrations \
29+
<<EOF
30+
set -e
31+
cargo build --locked --release
32+
cp ./target/release/$APP_NAME /bin/server
33+
EOF
34+
35+
################################################################################
36+
# Create a new stage for running the application that contains the minimal
37+
# runtime dependencies for the application. This often uses a different base
38+
# image from the build stage where the necessary files are copied from the build
39+
# stage.
40+
#
41+
# The example below uses the debian bullseye image as the foundation for running the app.
42+
# By specifying the "bullseye-slim" tag, it will also use whatever happens to be the
43+
# most recent version of that tag when you build your Dockerfile. If
44+
# reproducability is important, consider using a digest
45+
# (e.g., debian@sha256:ac707220fbd7b67fc19b112cee8170b41a9e97f703f588b2cdbbcdcecdd8af57).
46+
FROM debian:bullseye-slim AS final
47+
48+
# Create a non-privileged user that the app will run under.
49+
# See https://docs.docker.com/develop/develop-images/dockerfile_best-practices/ #user
50+
ARG UID=10001
51+
RUN adduser \
52+
--disabled-password \
53+
--gecos "" \
54+
--home "/nonexistent" \
55+
--shell "/sbin/nologin" \
56+
--no-create-home \
57+
--uid "${UID}" \
58+
appuser
59+
USER appuser
60+
61+
# Copy the executable from the "build" stage.
62+
COPY --from=build /bin/server /bin/
63+
64+
# Expose the port that the application listens on.
65+
EXPOSE 8000
66+
67+
# What the container should run when it is started.
68+
CMD ["/bin/server"]

README.Docker.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
### Building and running your application
2+
3+
When you're ready, start your application by running:
4+
`docker compose up --build`.
5+
6+
Your application will be available at http://localhost:8000.
7+
8+
### Deploying your application to the cloud
9+
10+
First, build your image, e.g.: `docker build -t myapp .`.
11+
If your cloud uses a different CPU architecture than your development
12+
machine (e.g., you are on a Mac M1 and your cloud provider is amd64),
13+
you'll want to build the image for that platform, e.g.:
14+
`docker build --platform=linux/amd64 -t myapp .`.
15+
16+
Then, push it to your registry, e.g. `docker push myregistry.com/myapp`.
17+
18+
Consult Docker's [getting started](https://docs.docker.com/go/get-started-sharing/)
19+
docs for more detail on building and pushing.
20+
21+
### References
22+
* [Docker's Rust guide](https://docs.docker.com/language/rust/)

compose.yaml

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# Comments are provided throughout this file to help you get started.
2+
# If you need more help, visit the Docker compose reference guide at
3+
# https://docs.docker.com/compose/compose-file/
4+
5+
# Here the instructions define your application as a service called "server".
6+
# This service is built from the Dockerfile in the current directory.
7+
# You can add other services your application may depend on here, such as a
8+
# database or a cache. For examples, see the Awesome Compose repository:
9+
# https://github.com/docker/awesome-compose
10+
services:
11+
server:
12+
build:
13+
context: .
14+
target: final
15+
ports:
16+
- 8000:8000
17+
environment:
18+
- PG_DBNAME=example
19+
- PG_HOST=db
20+
- PG_USER=postgres
21+
- PG_PASSWORD=mysecretpassword
22+
- ADDRESS=0.0.0.0:8000
23+
- RUST_LOG=debug
24+
# The commented out section below is an example of how to define a PostgreSQL
25+
# database that your application can use. `depends_on` tells Docker Compose to
26+
# start the database before your application. The `db-data` volume persists the
27+
# database data between container restarts. The `db-password` secret is used
28+
# to set the database password. You must create `db/password.txt` and add
29+
# a password of your choosing to it before running `docker compose up`.
30+
depends_on:
31+
db:
32+
condition: service_healthy
33+
db:
34+
image: postgres
35+
restart: always
36+
user: postgres
37+
secrets:
38+
- db-password
39+
volumes:
40+
- db-data:/var/lib/postgresql/data
41+
environment:
42+
- POSTGRES_DB=example
43+
- POSTGRES_PASSWORD_FILE=/run/secrets/db-password
44+
expose:
45+
- 5432
46+
healthcheck:
47+
test: [ "CMD", "pg_isready" ]
48+
interval: 10s
49+
timeout: 5s
50+
retries: 5
51+
volumes:
52+
db-data:
53+
secrets:
54+
db-password:
55+
file: db/password.txt

db/password.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
mysecretpassword

migrations/.gitkeep

Whitespace-only changes.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
DROP TABLE users;
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
CREATE TABLE users (
2+
id SERIAL PRIMARY KEY,
3+
login TEXT UNIQUE NOT NULL
4+
);
5+
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
INSERT INTO users (login) VALUES ('root');

0 commit comments

Comments
 (0)