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

chore: dockerize #384

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 8 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
15 changes: 7 additions & 8 deletions api/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,21 @@ ARG VERSION

RUN apk add --update --no-cache git ca-certificates build-base

COPY go.mod go.sum main.go /reearth-flow/
WORKDIR /reearth-flow
COPY go.mod go.sum main.go /api/
WORKDIR /api
RUN go mod download

COPY cmd/ /reearth-flow/cmd/
COPY pkg/ /reearth-flow/pkg/
COPY internal/ /reearth-flow/internal/
COPY cmd/ /api/cmd/
COPY pkg/ /api/pkg/
COPY internal/ /api/internal/

RUN CGO_ENABLED=0 go build -tags "${TAG}" "-ldflags=-X main.version=${VERSION} -s -w -buildid=" -trimpath ./cmd/reearth-flow

FROM scratch

COPY --from=build /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt
COPY --from=build /reearth/reearth-flow /reearth/reearth-flow
COPY ui* /reearth/ui/
COPY --from=build /api /api

WORKDIR /reearth-flow
WORKDIR /api

CMD [ "./reearth-flow" ]
23 changes: 0 additions & 23 deletions api/docker-compose.yml

This file was deleted.

44 changes: 44 additions & 0 deletions compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
version: "3.9"
services:
api:
build:
context: ./api/
dockerfile: Dockerfile
environment:
REEARTH_FLOW_DB: mongodb://mongo
ports:
- "8081:8081"
env_file:
- ./api/.env
depends_on:
- mongo

mongo:
image: mongo:6-focal
volumes:
- type: volume
source: reearth-flow-mongo
target: /data/db
volume:
nocopy: true
command: mongod --port 27017 --bind_ip_all

websocket:
build:
context: ./websocket/
dockerfile: Dockerfile
ports:
- "8000:8000"

ui:
build:
context: ./ui/
dockerfile: Dockerfile
env_file:
- ./ui/.env
ports:
- "3000:3000"

volumes:
reearth-flow-mongo:
driver: local
1 change: 1 addition & 0 deletions ui/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
./node_modules
20 changes: 5 additions & 15 deletions ui/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,19 +1,9 @@
FROM node:lts as build
FROM node:20.16-bullseye-slim

COPY package.json yarn.lock ./

RUN yarn install
WORKDIR /app

RUN corepack enable && corepack prepare [email protected] --activate
COPY . .
RUN yarn install

RUN yarn build

FROM nginx:stable

RUN rm /etc/nginx/conf.d/default.conf

COPY nginx.conf /etc/nginx/conf.d

COPY --from=build ./dist /usr/share/nginx/html

CMD ["nginx", "-g", "daemon off;"]
CMD ["yarn", "start", "--host"]
11 changes: 0 additions & 11 deletions ui/docker-compose.yml

This file was deleted.

1 change: 1 addition & 0 deletions websocket/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
./target/
73 changes: 49 additions & 24 deletions websocket/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions websocket/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
[workspace]
members = [
"crates/*",
"bin",
]

resolver = "2"
Expand Down Expand Up @@ -36,6 +37,7 @@ strip = true

[workspace.dependencies]
flow-websocket-domain = {path = "crates/domain"}
flow-websocket-infra = {path = "crates/infra"}

async-trait = "0.1.80"
axum = {version = "0.7", features = ["ws"]}
Expand Down
13 changes: 13 additions & 0 deletions websocket/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
FROM rust:1.80-slim-bullseye AS builder

COPY . /websocket/
WORKDIR /websocket
RUN apt update
RUN apt install -y build-essential pkg-config libssl-dev
RUN cargo build --release

FROM debian:bullseye-slim

COPY --from=builder /websocket/target/release/server /usr/local/bin/

CMD ["server"]
32 changes: 32 additions & 0 deletions websocket/bin/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
[package]
name = "server"

authors.workspace = true
edition.workspace = true
homepage.workspace = true
license.workspace = true
repository.workspace = true
rust-version.workspace = true
version.workspace = true

[dependencies]
flow-websocket-domain.workspace = true
flow-websocket-infra.workspace = true

async-trait.workspace = true
axum-extra.workspace = true
axum-macros.workspace = true
axum.workspace = true
chrono.workspace = true
google-cloud-storage.workspace = true
redis.workspace = true
rslock.workspace = true
serde.workspace = true
serde_json.workspace = true
tokio.workspace = true
tower-http.workspace = true
tower.workspace = true
tracing-subscriber.workspace = true
tracing.workspace = true
uuid.workspace = true
yrs.workspace = true
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::{net::SocketAddr, sync::Arc, time::Duration};

use axum::{error_handling::HandleErrorLayer, routing::get, Router};
use socket::{
use flow_websocket_infra::socket::{
handler::{handle_error, handle_upgrade},
state::AppState,
};
Expand All @@ -12,14 +12,13 @@ use tower_http::{
trace::{DefaultMakeSpan, TraceLayer},
};
use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt};
mod socket;

#[tokio::main]
async fn main() -> std::io::Result<()> {
tracing_subscriber::registry()
.with(
tracing_subscriber::EnvFilter::try_from_default_env()
.unwrap_or_else(|_| "example_websockets=debug,tower_http=debug".into()),
.unwrap_or_else(|_| "server=debug,tower_http=debug".into()),
)
.with(tracing_subscriber::fmt::layer())
.init();
Expand All @@ -43,9 +42,7 @@ async fn main() -> std::io::Result<()> {
)
.with_state(state);

let listener = tokio::net::TcpListener::bind("127.0.0.1:8000")
.await
.unwrap();
let listener = tokio::net::TcpListener::bind("0.0.0.0:8000").await.unwrap();
tracing::debug!("listening on {}", listener.local_addr().unwrap());
axum::serve(
listener,
Expand Down
2 changes: 1 addition & 1 deletion websocket/crates/infra/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
description = "Re:Earth Flow Websocket Domain library"
name = "infra"
name = "flow-websocket-infra"

authors.workspace = true
edition.workspace = true
Expand Down
1 change: 0 additions & 1 deletion worker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# syntax=docker/dockerfile:1
FROM rust:1.80-slim-bookworm AS builder

ARG NAME=reearth-flow
Expand Down
Loading