build: add docker build files

This commit is contained in:
Alexander Navarro 2025-03-12 15:11:48 -03:00
parent 1871610770
commit 3c2d3cf720
6 changed files with 262 additions and 23 deletions

View file

@ -0,0 +1,38 @@
services:
compendium:
image: compendium:latest
restart: unless-stopped
depends_on:
- db
ports:
- 3000:3000
env_file:
- ../../.env
db:
image: postgres:17-alpine
ports:
- 5432:5432
environment:
POSTGRES_USER: ${CPD_DB_USER}
POSTGRES_PASSWORD: ${CPD_DB_PASSWORD}
POSTGRES_DB: ${CPD_DB_NAME}
adminer:
image: ghcr.io/shyim/adminerevo:latest
ports:
- 8080:8080
environment:
ADMINER_DEFAULT_DRIVER: psql
ADMINER_DEFAULT_SERVER: db
ADMINER_DEFAULT_USER: ${CPD_DB_USER}
ADMINER_DEFAULT_PASSWORD: ${CPD_DB_PASSWORD}
ADMINER_DEFAULT_DB: ${CPD_DB_NAME}
dbmate:
image: ghcr.io/amacneil/dbmate
restart: no
command: ["--wait", "migrate"]
volumes:
- ${PWD}/db:/db
environment:
DATABASE_URL: postgres://${CPD_DB_USER}:${CPD_DB_PASSWORD}@db:5432/${CPD_DB_NAME}?sslmode=disable

View file

@ -0,0 +1,20 @@
import sassPlugin from "@alecodes/bun-plugin-sass";
const entrypoints = Array.from(
new Bun.Glob("frontend/**/*.html").scanSync("."),
);
const result = await Bun.build({
entrypoints,
outdir: "dist",
publicPath: "/",
splitting: true,
plugins: [sassPlugin],
naming: {
entry: "[dir]/[name].[ext]",
chunk: "assets/[name]-[hash].[ext]",
asset: "assets/[name]-[hash].[ext]",
},
});
console.log("Assets compiled!");

149
.dockerignore Normal file
View file

@ -0,0 +1,149 @@
# Devfiles
.devfiles/bin/**/*
dist
#### -- TEMPLATES BEGIN -- ####
### Node
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*
.pnpm-debug.log*
# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
# Runtime data
pids
*.pid
*.seed
*.pid.lock
# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov
# Coverage directory used by tools like istanbul
coverage
*.lcov
# nyc test coverage
.nyc_output
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
.grunt
# Bower dependency directory (https://bower.io/)
bower_components
# node-waf configuration
.lock-wscript
# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release
# Dependency directories
node_modules/
jspm_packages/
# Snowpack dependency directory (https://snowpack.dev/)
web_modules/
# TypeScript cache
*.tsbuildinfo
# Optional npm cache directory
.npm
# Optional eslint cache
.eslintcache
# Optional stylelint cache
.stylelintcache
# Microbundle cache
.rpt2_cache/
.rts2_cache_cjs/
.rts2_cache_es/
.rts2_cache_umd/
# Optional REPL history
.node_repl_history
# Output of 'npm pack'
*.tgz
# Yarn Integrity file
.yarn-integrity
# dotenv environment variable files
.env
.env.development.local
.env.test.local
.env.production.local
.env.local
# parcel-bundler cache (https://parceljs.org/)
.cache
.parcel-cache
# Next.js build output
.next
out
# Nuxt.js build / generate output
.nuxt
dist
# Gatsby files
.cache/
# Comment in the public line in if your project uses Gatsby and not Next.js
# https://nextjs.org/blog/next-9-1#public-directory-support
# public
# vuepress build output
.vuepress/dist
# vuepress v2.x temp and cache directory
.temp
.cache
# Docusaurus cache and generated files
.docusaurus
# Serverless directories
.serverless/
# FuseBox cache
.fusebox/
# DynamoDB Local files
.dynamodb/
# TernJS port file
.tern-port
# Stores VSCode versions used for testing VSCode extensions
.vscode-test
# yarn v2
.yarn/cache
.yarn/unplugged
.yarn/build-state.yml
.yarn/install-state.gz
.pnp.*
#### -- TEMPLATES END -- ####
# Allow to presever folder structure in excluded folers, should be the last rule
!**/.gitkeep
# Added by cargo
/target
.env

View file

@ -3,6 +3,8 @@ mod repo ".devfiles/justfile"
set dotenv-load := true
release_mode := "dev"
[private]
docker-compose +ARGS:
docker compose --file .devfiles/docker/docker-compose.dev.yaml --env-file .env --project-name compendium {{ARGS}}
@ -10,7 +12,14 @@ docker-compose +ARGS:
start-dev-services: (docker-compose "up --remove-orphans")
dev:
watchexec --no-vcs-ignore --clear --restart --watch=dist --watch=src cargo run
watchexec --no-vcs-ignore --clear --restart --watch=dist --watch=src cargo run {{ if release_mode == "prod" { "--release" } else { "" } }}
kitty-dev:
kitten @ goto-layout tall
kitten @ launch --cwd=current --dont-take-focus just build-frontend-watch
kitten @ launch --cwd=current --dont-take-focus just start-dev-services
kitten @ launch --cwd=current --dont-take-focus just dev
nvim ./src/main.rs
migrate: (docker-compose "run dbmate migrate")
@ -20,24 +29,4 @@ build-frontend-watch:
watchexec --restart --watch frontend just build-frontend
build-frontend:
#!/usr/bin/env bun
import sassPlugin from "@alecodes/bun-plugin-sass";
const entrypoints = Array.from(
new Bun.Glob("frontend/**/*.html").scanSync(".")
);
const result = await Bun.build({
entrypoints,
outdir: "dist",
publicPath: "/",
splitting: true,
plugins: [sassPlugin],
naming: {
entry: "[dir]/[name].[ext]",
chunk: "assets/[name]-[hash].[ext]",
asset: "assets/[name]-[hash].[ext]",
},
});
console.log("Assets compiled!");
bun ./.devfiles/scripts/build-frontend.ts

43
Dockerfile Normal file
View file

@ -0,0 +1,43 @@
# ── Javascript ──────────────────────────────────────────────────────────
FROM oven/bun:1 AS base-js
WORKDIR /usr/src/app
# install dependencies into temp directory
# this will cache them and speed up future builds
FROM base-js AS install
COPY package.json bun.lock /temp/dev/
RUN cd /temp/dev && bun install --frozen-lockfile
# copy node_modules from temp directory
# then copy all (non-ignored) project files into the image
FROM base-js AS prerelease
COPY --from=install /temp/dev/node_modules node_modules
COPY frontend frontend
COPY .devfiles/scripts/build-frontend.ts .devfiles/scripts/build-frontend.ts
ENV NODE_ENV=production
RUN bun ./.devfiles/scripts/build-frontend.ts
# ── Rust ────────────────────────────────────────────────────────────────
FROM rust:slim AS base-rust
WORKDIR /app
COPY . .
COPY --from=prerelease /usr/src/app/dist dist
RUN cargo build --locked --release
FROM scratch AS runner
ENV RUST_LOG="compendium=debug,info"
COPY --from=base-rust /app/target/release/compendium /
EXPOSE 3000
ENTRYPOINT ["./compendium"]
CMD ["./compendium"]

View file

@ -6,7 +6,7 @@
<button class="msp-btn-sm" hx-get="/" hx-target="#example-table">Refresh</button>
</div>
<h1>Axum example! 1</h1>
<h1>Axum example!</h1>
{% block htmx %}
<table id="example-table">