Skip to content

Database governance built for humans and agents — controlling changes and access across every major database.

chore: simplify Docker files (#1945)

Yilong Li3208e7dcb7d3
diff --git a/Dockerfile b/Dockerfile
index 0b75ce71a5..6ceeefb428 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -42,9 +42,11 @@ COPY . .
# Copy frontend asset
COPY --from=frontend /frontend-build/dist ./server/dist
+COPY ./scripts/VERSION .
+
# -ldflags="-w -s" means omit DWARF symbol table and the symbol table and debug information
# go-sqlite3 requires CGO_ENABLED
-RUN CGO_ENABLED=1 GOOS=linux GOARCH=amd64 go build \
+RUN VERSION=`cat ./VERSION` && CGO_ENABLED=1 GOOS=linux GOARCH=amd64 go build \
--tags "${RELEASE},embed_frontend" \
-ldflags="-w -s -X 'github.com/bytebase/bytebase/bin/server/cmd.version=${VERSION}' -X 'github.com/bytebase/bytebase/bin/server/cmd.goversion=${GO_VERSION}' -X 'github.com/bytebase/bytebase/bin/server/cmd.gitcommit=${GIT_COMMIT}' -X 'github.com/bytebase/bytebase/bin/server/cmd.buildtime=${BUILD_TIME}' -X 'github.com/bytebase/bytebase/bin/server/cmd.builduser=${BUILD_USER}'" \
-o bytebase \
@@ -65,7 +67,8 @@ LABEL org.opencontainers.image.created=${BUILD_TIME}
LABEL org.opencontainers.image.authors=${BUILD_USER}
# Our HEALTHCHECK instruction in dockerfile needs curl.
-RUN apt-get update && apt-get install -y locales curl
+# Install psmisc to use killall command in demo.sh used by render.com.
+RUN apt-get update && apt-get install -y locales curl psmisc
# Generate en_US.UTF-8 locale which is needed to start postgres server.
# Fix the posgres server issue (invalid value for parameter "lc_messages": "en_US.UTF-8").
RUN echo "en_US.UTF-8 UTF-8" > /etc/locale.gen && locale-gen
diff --git a/Dockerfile.render b/Dockerfile.render-demo
similarity index 74%
rename from Dockerfile.render
rename to Dockerfile.render-demo
index 02f47587de..225a7ba7c5 100644
--- a/Dockerfile.render
+++ b/Dockerfile.render-demo
@@ -1,7 +1,9 @@
-# This script is for demo.bytebase.com and staging.bytebase.com on Render ONLY
+# This script is for PR preview and demo.bytebase.com on Render ONLY.
FROM node:14 as frontend
+ARG RELEASE="dev"
+
RUN npm i -g pnpm
WORKDIR /frontend-build
@@ -13,17 +15,17 @@ RUN pnpm install --frozen-lockfile
COPY ./frontend/ .
# Build frontend
-RUN pnpm release-docker
+RUN pnpm "${RELEASE}-docker"
FROM golang:1.18.4 as backend
-ARG VERSION="development"
-ARG GO_VERSION="1.18.4"
+ARG GO_VERSION="unknown"
+# RENDER_GIT_COMMIT is a render.com provided env var during build.
+# https://render.com/docs/environment-variables
ARG RENDER_GIT_COMMIT="unknown"
ARG BUILD_TIME="unknown"
ARG BUILD_USER="unknown"
-# Build in release mode so we will embed the frontend
ARG RELEASE="release"
# Need gcc for CGO_ENABLED=1
@@ -36,14 +38,13 @@ COPY . .
# Copy frontend asset
COPY --from=frontend /frontend-build/dist ./server/dist
-# For VERSION info
-COPY ./scripts .
+COPY ./scripts/VERSION .
# -ldflags="-w -s" means omit DWARF symbol table and the symbol table and debug information
# go-sqlite3 requires CGO_ENABLED
-RUN CMD_VERSION=`cat ./VERSION` && CGO_ENABLED=1 GOOS=linux GOARCH=amd64 go build \
+RUN VERSION=`cat ./VERSION` && CGO_ENABLED=1 GOOS=linux GOARCH=amd64 go build \
--tags "${RELEASE},embed_frontend" \
- -ldflags="-w -s -X 'github.com/bytebase/bytebase/bin/server/cmd.version=${CMD_VERSION}' -X 'github.com/bytebase/bytebase/bin/server/cmd.goversion=${GO_VERSION}' -X 'github.com/bytebase/bytebase/bin/server/cmd.gitcommit=${RENDER_GIT_COMMIT}' -X 'github.com/bytebase/bytebase/bin/server/cmd.buildtime=${BUILD_TIME}' -X 'github.com/bytebase/bytebase/bin/server/cmd.builduser=${BUILD_USER}'" \
+ -ldflags="-w -s -X 'github.com/bytebase/bytebase/bin/server/cmd.version=${VERSION}' -X 'github.com/bytebase/bytebase/bin/server/cmd.goversion=${GO_VERSION}' -X 'github.com/bytebase/bytebase/bin/server/cmd.gitcommit=${RENDER_GIT_COMMIT}' -X 'github.com/bytebase/bytebase/bin/server/cmd.buildtime=${BUILD_TIME}' -X 'github.com/bytebase/bytebase/bin/server/cmd.builduser=${BUILD_USER}'" \
-o bytebase \
./bin/server/main.go
@@ -62,13 +63,14 @@ LABEL org.opencontainers.image.created=${BUILD_TIME}
LABEL org.opencontainers.image.authors=${BUILD_USER}
# Our HEALTHCHECK instruction in dockerfile needs curl.
-# Install psmisc to use killall command in demo.sh.
+# Install psmisc to use killall command in demo.sh used by render.com.
RUN apt-get update && apt-get install -y locales curl psmisc
# Generate en_US.UTF-8 locale which is needed to start postgres server.
# Fix the posgres server issue (invalid value for parameter "lc_messages": "en_US.UTF-8").
RUN echo "en_US.UTF-8 UTF-8" > /etc/locale.gen && locale-gen
COPY --from=backend /backend-build/bytebase /usr/local/bin/
+COPY --from=backend /etc/ssl/certs /etc/ssl/certs
# Copy utility scripts, we have
# - Demo script to launch Bytebase in readonly demo mode
diff --git a/Dockerfile.render-preview b/Dockerfile.render-preview
deleted file mode 100644
index 80e774ee01..0000000000
--- a/Dockerfile.render-preview
+++ /dev/null
@@ -1,83 +0,0 @@
-# *****************************************************
-# * This script is for PR preview purpose on Render ONLY *
-# *****************************************************
-
-FROM node:14 as frontend
-
-RUN npm i -g pnpm
-
-WORKDIR /frontend-build
-
-# Install build dependency (e.g. vite)
-COPY ./frontend/package.json ./frontend/pnpm-lock.yaml ./
-RUN pnpm install --frozen-lockfile
-
-COPY ./frontend/ .
-
-# Build frontend
-RUN pnpm release-docker
-
-FROM golang:1.18.4 as backend
-
-ARG VERSION="development"
-ARG GO_VERSION="unknown"
-ARG RENDER_GIT_COMMIT="unknown"
-ARG BUILD_TIME="unknown"
-ARG BUILD_USER="unknown"
-
-# Build in release mode so we will embed the frontend
-ARG RELEASE="release"
-
-# Need gcc for CGO_ENABLED=1
-RUN apt-get install -y gcc
-
-WORKDIR /backend-build
-
-COPY . .
-
-# Copy frontend asset
-COPY --from=frontend /frontend-build/dist ./server/dist
-
-# For VERSION info
-COPY ./scripts .
-
-# -ldflags="-w -s" means omit DWARF symbol table and the symbol table and debug information
-# go-sqlite3 requires CGO_ENABLED
-RUN CMD_VERSION=`cat ./VERSION` && CGO_ENABLED=1 GOOS=linux GOARCH=amd64 go build \
- --tags "${RELEASE},embed_frontend" \
- -ldflags="-w -s -X 'github.com/bytebase/bytebase/bin/server/cmd.version=${CMD_VERSION}' -X 'github.com/bytebase/bytebase/bin/server/cmd.goversion=${GO_VERSION}' -X 'github.com/bytebase/bytebase/bin/server/cmd.gitcommit=${RENDER_GIT_COMMIT}' -X 'github.com/bytebase/bytebase/bin/server/cmd.buildtime=${BUILD_TIME}' -X 'github.com/bytebase/bytebase/bin/server/cmd.builduser=${BUILD_USER}'" \
- -o bytebase \
- ./bin/server/main.go
-
-# Use debian because mysql requires glibc.
-FROM debian:bullseye-slim as monolithic
-
-ARG VERSION="development"
-ARG RENDER_GIT_COMMIT="unknown"
-ARG BUILD_TIME="unknown"
-ARG BUILD_USER="unknown"
-
-# See https://github.com/opencontainers/image-spec/blob/master/annotations.md
-LABEL org.opencontainers.image.version=${VERSION}
-LABEL org.opencontainers.image.revision=${RENDER_GIT_COMMIT}
-LABEL org.opencontainers.image.created=${BUILD_TIME}
-LABEL org.opencontainers.image.authors=${BUILD_USER}
-
-# Our HEALTHCHECK instruction in dockerfile needs curl.
-# Install psmisc to use killall command in demo.sh.
-RUN apt-get update && apt-get install -y locales curl psmisc
-# Generate en_US.UTF-8 locale which is needed to start postgres server.
-# Fix the posgres server issue (invalid value for parameter "lc_messages": "en_US.UTF-8").
-RUN echo "en_US.UTF-8 UTF-8" > /etc/locale.gen && locale-gen
-
-COPY --from=backend /backend-build/bytebase /usr/local/bin/
-
-# Copy utility scripts, we have
-# - Demo script to launch Bytebase in readonly demo mode
-COPY ./scripts /usr/local/bin/
-
-# Create user "bytebase" for running Postgres database and server.
-RUN addgroup --gid 113 --system bytebase && adduser --uid 113 --system bytebase && adduser bytebase bytebase
-
-# Directory to store the data, which can be referenced as the mounting point.
-RUN mkdir -p /var/opt/bytebase