Skip to content
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
73 changes: 43 additions & 30 deletions .air.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,41 +3,54 @@ testdata_dir = "testdata"
tmp_dir = "tmp"

[build]
args_bin = []
bin = "./tmp/main"
cmd = "go build -o ./tmp/main main.go"
delay = 2000
exclude_dir = ["assets", "tmp", "vendor", "testdata", "views", "node_modules", "data", "web", "scripts", "utils/testdir"]
exclude_unchanged = false
follow_symlink = false
full_bin = ""
include_ext = ["go", "tpl", "tmpl"]
include_file = []
kill_delay = "1s"
log = "build-errors.log"
poll = false
poll_interval = 0
post_cmd = []
pre_cmd = []
rerun = false
rerun_delay = 50
send_interrupt = true
stop_on_error = true
args_bin = []
bin = "./tmp/main"
cmd = "go build -o ./tmp/main main.go"
delay = 2000
exclude_dir = [
"assets",
"tmp",
"vendor",
"testdata",
"views",
"node_modules",
"data",
"web",
"scripts",
"utils/testdir",
"postgres_data",
"minio_data",
]
exclude_unchanged = false
follow_symlink = false
full_bin = ""
include_ext = ["go", "tpl", "tmpl"]
include_file = []
kill_delay = "1s"
log = "build-errors.log"
poll = false
poll_interval = 0
post_cmd = []
pre_cmd = []
rerun = false
rerun_delay = 50
send_interrupt = true
stop_on_error = true

[color]
app = ""
build = "yellow"
main = "magenta"
runner = "green"
watcher = "cyan"
app = ""
build = "yellow"
main = "magenta"
runner = "green"
watcher = "cyan"

[log]
main_only = false
time = false
main_only = false
time = false

[misc]
clean_on_exit = false
clean_on_exit = false

[screen]
clear_on_rebuild = false
keep_scroll = true
clear_on_rebuild = false
keep_scroll = true
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,5 @@ dist/
data/
web/build/*
.vscode/
postgres_data/
minio_data/
19 changes: 17 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
# Build stage for web assets
FROM node:20 AS web-builder

# pnpm setup
ENV PNPM_HOME="/pnpm"
ENV PATH="$PNPM_HOME:$PATH"
RUN corepack enable && corepack prepare pnpm@latest --activate

WORKDIR /app/web
COPY web/package*.json ./
RUN npm install
COPY web/pnpm*.yaml ./
# RUN npm install
RUN --mount=type=cache,id=pnpm,target=/pnpm/store pnpm install --frozen-lockfile
COPY web ./
RUN npm run build
# RUN npm run build
RUN pnpm run build

# Build stage for Go application
FROM golang:1.23-bookworm AS go-builder
Expand All @@ -30,6 +39,12 @@ RUN chmod +x /build.sh && /build.sh
FROM node:20-slim
WORKDIR /app

# pnpm setup
ENV PNPM_HOME="/pnpm"
ENV PATH="$PNPM_HOME:$PATH"
RUN corepack enable && corepack prepare pnpm@latest --activate
RUN which pnpm

# Copy built artifacts
COPY --from=go-builder /app/kalmia .
COPY --from=web-builder /app/web/build ./web/build
Expand Down
5 changes: 5 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,8 @@ build: clean build-linux-amd64 build-linux-386 build-linux-arm build-linux-arm64

clean:
rm -rf dist

docker-clean:
sudo rm -rf ./postgres_data ./minio_data
docker rm kalmia-postgres-1 kalmia-app-1 kalmia-minio-1 kalmia-createbuckets-1 && docker rmi kalmia-app

31 changes: 28 additions & 3 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ var ParsedConfig *Config

func ParseConfig(path string) *Config {
file, err := os.Open(path)

if err != nil {
panic(err)
}
Expand All @@ -71,16 +70,19 @@ func ParseConfig(path string) *Config {
decoder := json.NewDecoder(file)
ParsedConfig = &Config{}
err = decoder.Decode(ParsedConfig)

if err != nil {
panic(err)
}

err = SetupDataPath()

if err != nil {
panic(err)
}

if ParsedConfig.AssetStorage == "local" {
SetupLocalS3Storage()
}

// INFO: Adds the default max file size of 10
// Added for backwards compatibility
if ParsedConfig.MaxFileSize == 0 {
Expand Down Expand Up @@ -111,3 +113,26 @@ func SetupDataPath() error {

return nil
}

func SetupLocalS3Storage() {
if ParsedConfig.Environment == "dev" {
ParsedConfig.S3.Endpoint = "http://localhost:9000"
} else {
ParsedConfig.S3.Endpoint = "http://minio:9000"
}
envAccessKeyID := os.Getenv("KAL_MINIO_ROOT_USER")
envSecretAccessKey := os.Getenv("KAL_MINIO_ROOT_PASSWORD")
if len(envAccessKeyID) == 0 {
envAccessKeyID = "minio_kalmia_user"
}
if len(envSecretAccessKey) == 0 {
envSecretAccessKey = "minio_kalmia_password"
}
ParsedConfig.S3.AccessKeyId = envAccessKeyID
ParsedConfig.S3.SecretAccessKey = envSecretAccessKey
ParsedConfig.S3.Bucket = "uploads"
ParsedConfig.S3.UsePathStyle = true
ParsedConfig.S3.Region = "auto"
// TODO: change this to be something different/dynamic which could be fetched as per config
ParsedConfig.S3.PublicUrlFormat = "http://localhost:9000/%s/%s"
}
58 changes: 58 additions & 0 deletions docker-compose-dev.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
services:
# app:
# # build:
# # context: .
# # dockerfile: Dockerfile
# ports:
# - "${PORT:-2727}:2727"
# volumes:
# - ./config.json:/app/config.json
# environment:
# - DATABASE_TYPE=postgres
# - DATABASE_HOST=postgres
# - DATABASE_USER=${POSTGRES_USER:-user}
# - DATABASE_NAME=kalmia
# - DATABASE_PASSWORD=${POSTGRES_PASSWORD:-password}
# depends_on:
# postgres:
# condition: service_healthy

postgres:
image: postgres:15
environment:
POSTGRES_USER: ${POSTGRES_USER:-user}
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-password}
POSTGRES_DB: kalmia
volumes:
- ./postgres_data:/var/lib/postgresql/data
healthcheck:
test: ["CMD-SHELL", "pg_isready -U ${POSTGRES_USER:-user} -d kalmia"]
interval: 10s
timeout: 10s
retries: 10

minio:
image: minio/minio:latest
ports:
- "9000:9000" # S3 API port
- "9001:9001" # MinIO Console
volumes:
- ./minio_data:/data
environment:
MINIO_ROOT_USER: ${KAL_MINIO_ROOT_USER:-minio_kalmia_user}
MINIO_ROOT_PASSWORD: ${KAL_MINIO_ROOT_PASSWORD:-minio_kalmia_password}
MINIO_BUCKETS: "uploads"
command: server --console-address ":9001" /data

createbuckets:
image: minio/mc
depends_on:
- minio
entrypoint: >
/bin/sh -c "
sleep 5;
mc alias set local http://minio:9000 minio_kalmia_user minio_kalmia_password;
mc mb local/uploads;
mc anonymous set download local/uploads;
exit 0;
"
26 changes: 26 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,29 @@ services:
interval: 10s
timeout: 10s
retries: 10

minio:
image: minio/minio:latest
ports:
- "9000:9000" # S3 API port
- "9001:9001" # MinIO Console
volumes:
- ./minio_data:/data
environment:
MINIO_ROOT_USER: ${KAL_MINIO_ROOT_USER:-minio_kalmia_user}
MINIO_ROOT_PASSWORD: ${KAL_MINIO_ROOT_PASSWORD:-minio_kalmia_password}
MINIO_BUCKETS: "uploads"
command: server --console-address ":9001" /data

createbuckets:
image: minio/mc
depends_on:
- minio
entrypoint: >
/bin/sh -c "
sleep 5;
mc alias set local http://minio:9000 minio_kalmia_user minio_kalmia_password;
mc mb local/uploads;
mc anonymous set download local/uploads;
exit 0;
"
Loading
Loading