Skip to content

Commit

Permalink
ci(docker): remove node and reduce layers (#92)
Browse files Browse the repository at this point in the history
  • Loading branch information
ayuhito authored Jul 9, 2024
1 parent d4547e2 commit 9958b7d
Showing 1 changed file with 17 additions and 25 deletions.
42 changes: 17 additions & 25 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,34 +3,26 @@
FROM jdxcode/mise:latest AS build

# Install unzip dependency for bun
RUN apt-get update && apt-get install -y unzip

# Install runtimes - Temporarily include node for google-closure-compiler for tracker
RUN mise use -g node@20
RUN mise use -g bun@latest
RUN mise use -g [email protected]

# Install Taskfile
RUN sh -c "$(curl --location https://taskfile.dev/install.sh)" -- -d -b ~/bin
# Also combine RUN commands to reduce layers
RUN apt-get update && apt-get install -y unzip && \
mise use -g bun@latest && \
mise use -g [email protected] && \
sh -c "$(curl --location https://taskfile.dev/install.sh)" -- -d -b ~/bin

# Cache build dependencies
ENV GOCACHE=/root/.cache/go-build

# Cache Go modules
WORKDIR /app
COPY /core/go.mod /core/go.sum ./core/

WORKDIR /app/core
RUN --mount=type=cache,target=/root/.cache/go-build \
--mount=type=cache,target=/go/pkg/mod \
go mod download

# Go back to root directory and install JavaScript dependencies
WORKDIR /app
COPY core/go.mod core/go.sum ./core/
COPY package.json bun.lockb ./
COPY dashboard/package.json ./dashboard/
COPY tracker/package.json ./tracker/
RUN bun install --frozen-lockfile

RUN --mount=type=cache,target=/root/.cache/go-build \
--mount=type=cache,target=/go/pkg/mod \
cd core && go mod download && cd .. && \
bun install --frozen-lockfile

# Copy the rest of the source code
COPY . .
Expand All @@ -39,13 +31,13 @@ RUN --mount=type=cache,target="/root/.cache/go-build" ~/bin/task core:release
# Build the final image
FROM gcr.io/distroless/cc-debian12

LABEL org.opencontainers.image.source=https://github.com/medama-io/medama
LABEL org.opencontainers.image.description="Cookie-free, privacy-focused website analytics."
LABEL org.opencontainers.image.licenses=Apache-2.0
LABEL org.opencontainers.image.source=https://github.com/medama-io/medama \
org.opencontainers.image.description="Cookie-free, privacy-focused website analytics." \
org.opencontainers.image.licenses=Apache-2.0

ENV PORT=8080
ENV ANALYTICS_DATABASE_HOST=/app/data/me_analytics.db
ENV APP_DATABASE_HOST=/app/data/me_app.db
ENV PORT=8080 \
ANALYTICS_DATABASE_HOST=/app/data/me_analytics.db \
APP_DATABASE_HOST=/app/data/me_app.db

WORKDIR /app

Expand Down

0 comments on commit 9958b7d

Please sign in to comment.