Initial docker file and stuff

This commit is contained in:
2023-09-24 17:41:48 -04:00
parent 9cf92b8c1f
commit 8d60a19b44
9 changed files with 5321 additions and 6 deletions

View File

@@ -23,6 +23,13 @@ down: ## Stop Docker service containers
connect: ## Connect to the Weather DB
docker exec -it ${DATABASE_CONTAINER} psql -U postgres
clean: ## Cleanup Docker containers
docker compose down && \
docker image rm weather-ui || \
docker image rm weather-service || \
docker network rm weather-frontend || \
docker network rm weather-backend
clean-db: ## Remove database
docker exec -i ${DATABASE_CONTAINER} sh -c 'PGPASSWORD=${DATABASE_PASSWORD} psql -U ${DATABASE_USER} -d postgres -c "DROP DATABASE IF EXISTS \"${DATABASE_NAME}\";"'
docker exec -i ${DATABASE_CONTAINER} sh -c 'PGPASSWORD=${DATABASE_PASSWORD} psql -U ${DATABASE_USER} -d postgres -c "CREATE DATABASE \"${DATABASE_NAME}\";"' || true

View File

@@ -16,6 +16,8 @@ services:
- db_logs:/var/log
ports:
- "${DATABASE_PORT}:5432"
networks:
- weather-backend
restart: unless-stopped
service:
@@ -23,11 +25,32 @@ services:
env_file:
- .env
ports:
- "${SERVICE_PORT}:${SERVICE_PORT}"
- "${SERVICE_PORT}:5000"
build:
context: service
depends_on:
- db
networks:
- weather-frontend
- weather-backend
restart: unless-stopped
ui:
container_name: weather-ui
env_file:
- .env
environment:
- NODE_ENV=${NODE_ENV}
ports:
- ${UI_PORT}:3000
build:
context: ui
target: dev
command: npm run dev
depends_on:
- service
networks:
- weather-frontend
restart: unless-stopped
volumes:
@@ -35,5 +58,5 @@ volumes:
db_logs:
networks:
default:
name: weather-backend
weather-frontend: {}
weather-backend: {}

12
service/Dockerfile Normal file
View File

@@ -0,0 +1,12 @@
FROM rust:1.72.1-bookworm
WORKDIR /service
USER root
COPY migrations ./migrations
COPY src ./src
COPY airport-codes.json Cargo.toml diesel.toml ./
RUN cargo build --release
CMD ["./target/release/weather-service"]

View File

@@ -45,7 +45,8 @@ async fn main() -> std::io::Result<()> {
Some(listener) => server.listen(listener)?,
None => {
let host = std::env::var("SERVICE_HOST").expect("Please set host in .env");
let port = std::env::var("SERVICE_PORT").expect("Please set port in .env");
// let port = std::env::var("SERVICE_PORT").expect("Please set port in .env");
let port = 5000;
debug!("Binding server to {}:{}", host, port);
server.bind(format!("{}:{}", host, port))?
}

1
ui/.nvmrc Normal file
View File

@@ -0,0 +1 @@
18.17.1

38
ui/Dockerfile Normal file
View File

@@ -0,0 +1,38 @@
# Base
FROM node:18-alpine AS base
# Dependencies
FROM base as deps
RUN apk add --no-cache libc6-compat
WORKDIR /app
COPY package.json package-lock.json ./
RUN npm ci
# Dev
FROM base AS dev
WORKDIR /app
COPY --from=deps /app/node_modules ./node_modules
COPY . .
# Builder
FROM base AS builder
WORKDIR /app
COPY --from=deps /app/node_modules ./node_modules
COPY . .
RUN npm run build
# Runner
FROM base AS runner
WORKDIR /app
RUN addgroup --system --gid 1001 nodejs && adduser --system --uid 1001 nextjs
COPY --from=builder /app/next.config.js ./
COPY --from=builder /app/public ./public
COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static
USER nextjs
EXPOSE 3000
ENV PORT 3000
ENV NEXT_TELEMETRY_DISABLED 1
CMD ["node", "server.js"]

View File

@@ -4,7 +4,19 @@ const nextConfig = {
swcMinify: true,
eslint: {
ignoreDuringBuilds: true
}
},
webpackDevMiddleware: (config) => {
config.watchOptions = {
poll: 1000,
aggregateTimeout: 300
};
return config;
},
publicRuntimeConfig: {
// remove private variables from processEnv
processEnv: Object.fromEntries(Object.entries(process.env).filter(([key]) => key.includes('NEXT_PUBLIC_')))
},
output: 'standalone'
};
module.exports = nextConfig;

5222
ui/package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -60,7 +60,6 @@ export default function MapTiles() {
}
function iconSize() {
console.log('zoom', zoomLevel);
if (zoomLevel <= 4) {
return 'text-xs';
} else if (zoomLevel <= 5) {