Skip to content

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

Add initial dockerfile and build_docker.sh

天舟614248f7d398
diff --git a/backend/Dockerfile b/backend/Dockerfile
new file mode 100644
index 0000000000..c9f8995f53
--- /dev/null
+++ b/backend/Dockerfile
@@ -0,0 +1,41 @@
+FROM golang:1.16.5-alpine3.13 as backend
+
+ARG VERSION="development"
+ARG GO_VERSION="unknown"
+ARG GIT_COMMIT="unknown"
+ARG BUILD_TIME="unknown"
+ARG BUILD_USER="unknown"
+
+# Need gcc musl-dev for CGO_ENABLED=1
+RUN apk --no-cache add gcc musl-dev
+
+WORKDIR /backend-build
+
+COPY . .
+
+# -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 \
+ -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 \
+ ./bin/server/main.go
+
+FROM alpine:3.14.0
+
+ARG VERSION="development"
+ARG GIT_COMMIT="unknown"
+ARG BUILD_TIME="unknown"
+ARG BUILD_USER="unknown"
+
+LABEL org.opencontainers.image.version=${VERSION}
+LABEL org.opencontainers.image.revision=${GIT_COMMIT}
+LABEL org.opencontainers.image.created=${BUILD_TIME}
+LABEL org.opencontainers.image.authors=${BUILD_USER}
+
+COPY --from=backend /backend-build/bytebase /usr/local/bin/
+
+RUN mkdir -p /var/opt/bytebase
+
+CMD ["--mode", "release", "--host", "http://localhost", "--port", "8080", "--data", "/var/opt/bytebase"]
+
+ENTRYPOINT ["bytebase"]
\ No newline at end of file
diff --git a/backend/build_docker.sh b/backend/build_docker.sh
new file mode 100755
index 0000000000..40146ea3d1
--- /dev/null
+++ b/backend/build_docker.sh
@@ -0,0 +1,11 @@
+#!/bin/sh
+
+version=0.1.0
+
+docker build \
+ --build-arg VERSION=${version} \
+ --build-arg GO_VERSION="$(go version)" \
+ --build-arg GIT_COMMIT="$(git rev-parse HEAD)"\
+ --build-arg BUILD_TIME="$(date -u +"%Y-%m-%dT%H:%M:%SZ")" \
+ --build-arg BUILD_USER="$(id -u -n)" \
+ -t bytebase/bytebase .
\ No newline at end of file