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

[WIP] docker周りのアップデート #70

Merged
merged 3 commits into from
Sep 5, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
36 changes: 36 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
FROM rust:1.71.1

ARG DATABASE_URL

ENV CARGO_TARGET_DIR=/tmp/target \
DEBIAN_FRONTEND=noninteractive \
LC_CTYPE=ja_JP.utf8 \
LANG=ja_JP.utf8 \
DATABASE_URL=${DATABASE_URL}

RUN sed -i.org -e 's|ports.ubuntu.com|jp.archive.ubuntu.com|g' /etc/apt/sources.list

RUN apt-get update \
&& apt-get install -y -q \
ca-certificates \
locales \
libpq-dev \
gnupg \
apt-transport-https\
libssl-dev \
pkg-config \
curl \
build-essential \
git \
wget \
&& echo "ja_JP UTF-8" > /etc/locale.gen \
&& locale-gen \
&& echo "install rust tools" \
&& cargo install sqlx-cli --no-default-features --features postgres

WORKDIR /app
COPY . .
ARG SQLX_OFFLINE=true
RUN cargo build --release

CMD ["bash", "./init.sh"]
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,15 @@
- Docker
- DockerCompose

以下の4つのURLを適切に設定します。

- `POSTGRES_DB`
- `POSTGRES_USER`
- `POSTGRES_PASSWORD`
- `DATABASE_URL`

そのうえで以下のコマンドを実行します。

```sh
docker-compose up -d
```
Expand Down
37 changes: 27 additions & 10 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,23 +1,40 @@
version: "3"


services:
api-server:
image: rust:latest
container_name: api-server
working_dir: /workspace
command: cargo run -- --bind 127.0.0.1:3000
tty: true
build:
context: .
volumes:
- ./:/workspace
- .:/app
ports:
- 3000:3000
environment:
DATABASE_URL: ${DATABASE_URL}
depends_on:
- db
networks:
- net
tty:
true
db:
image: postgres:15
environment:
- DATABASE_URL: ${DATABASE_URL:?}
container_name: postgres
working_dir: /app
ports:
- ${POSTGRES_PORT:?}:5432
- 5432:5432
restart: always
environment:
POSTGRES_USER: ${POSTGRES_USER}
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
POSTGRES_DB: ${POSTGRES_DB}
volumes:
- postgres-data-dev:/var/lib/postgresql/data
- "postgres_data_dev:/var/lib/postgresql"
networks:
- net
volumes:
postgres-data-dev:
postgres_data_dev:
networks:
net:
driver: bridge
4 changes: 4 additions & 0 deletions init.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash
sqlx db create
sqlx migrate run
cargo run --release -- --bind 0.0.0.0:3000
Loading