mirror of https://gitee.com/answerdev/answer.git
Merge branch 'ci/sqlite' into 'main'
ci: update dockerfile and makefile for sqlite embed issue See merge request opensource/answer!121
This commit is contained in:
commit
67b59cf1df
54
Dockerfile
54
Dockerfile
|
@ -6,40 +6,54 @@ COPY . /answer
|
|||
WORKDIR /answer
|
||||
RUN make install-ui-packages ui && mv ui/build /tmp
|
||||
|
||||
FROM golang:1.18 AS golang-builder
|
||||
LABEL maintainer="aichy"
|
||||
# stage2 build the main binary within static resource
|
||||
FROM golang:1.19-alpine AS golang-builder
|
||||
LABEL maintainer="aichy@sf.com"
|
||||
|
||||
ARG GOPROXY
|
||||
ENV GOPROXY ${GOPROXY:-direct}
|
||||
|
||||
ENV GOPATH /go
|
||||
ENV GOROOT /usr/local/go
|
||||
ENV PACKAGE github.com/answerdev/answer
|
||||
ENV GOPROXY https://goproxy.cn,direct
|
||||
ENV BUILD_DIR ${GOPATH}/src/${PACKAGE}
|
||||
# Build
|
||||
|
||||
ARG TAGS="sqlite sqlite_unlock_notify"
|
||||
ENV TAGS "bindata timetzdata $TAGS"
|
||||
ARG CGO_EXTRA_CFLAGS
|
||||
|
||||
COPY . ${BUILD_DIR}
|
||||
WORKDIR ${BUILD_DIR}
|
||||
COPY --from=node-builder /tmp/build ${BUILD_DIR}/ui/build
|
||||
RUN make clean build && \
|
||||
cp answer /usr/bin/answer && \
|
||||
mkdir -p /data/upfiles && chmod 777 /data/upfiles && \
|
||||
mkdir -p /data/i18n && chmod 777 /data/i18n && cp -r i18n/*.yaml /data/i18n
|
||||
RUN apk --no-cache add build-base git \
|
||||
&& make clean build \
|
||||
&& cp answer /usr/bin/answer
|
||||
|
||||
RUN mkdir -p /data/upfiles && chmod 777 /data/upfiles \
|
||||
&& mkdir -p /data/i18n && cp -r i18n/*.yaml /data/i18n
|
||||
|
||||
# stage3 copy the binary and resource files into fresh container
|
||||
FROM alpine
|
||||
LABEL maintainer="maintainers@sf.com"
|
||||
|
||||
FROM debian:bullseye
|
||||
ENV TZ "Asia/Shanghai"
|
||||
RUN sed -i 's/deb.debian.org/mirrors.tuna.tsinghua.edu.cn/g' /etc/apt/sources.list \
|
||||
&& sed -i 's/security.debian.org/mirrors.tuna.tsinghua.edu.cn/g' /etc/apt/sources.list \
|
||||
&& echo "Asia/Shanghai" > /etc/timezone \
|
||||
&& apt -y update \
|
||||
&& apt -y upgrade \
|
||||
&& apt -y install ca-certificates openssl tzdata curl netcat dumb-init \
|
||||
&& apt -y autoremove \
|
||||
&& mkdir -p /tmp/cache
|
||||
|
||||
COPY --from=golang-builder /data /data
|
||||
VOLUME /data
|
||||
RUN apk update \
|
||||
&& apk --no-cache add \
|
||||
bash \
|
||||
ca-certificates \
|
||||
curl \
|
||||
dumb-init \
|
||||
gettext \
|
||||
openssh \
|
||||
sqlite \
|
||||
gnupg \
|
||||
&& echo "Asia/Shanghai" > /etc/timezone
|
||||
|
||||
COPY --from=golang-builder /usr/bin/answer /usr/bin/answer
|
||||
COPY --from=golang-builder /data /data
|
||||
COPY /script/entrypoint.sh /entrypoint.sh
|
||||
RUN chmod 755 /entrypoint.sh
|
||||
|
||||
VOLUME /data
|
||||
EXPOSE 80
|
||||
ENTRYPOINT ["/entrypoint.sh"]
|
||||
|
|
2
Makefile
2
Makefile
|
@ -7,7 +7,7 @@ DOCKER_CMD=docker
|
|||
|
||||
#GO_ENV=CGO_ENABLED=0
|
||||
Revision=$(shell git rev-parse --short HEAD)
|
||||
GO_FLAGS=-ldflags="-X main.Version=$(VERSION) -X main.Revision=$(Revision) -X 'main.Time=`date`' -extldflags -static"
|
||||
GO_FLAGS=-ldflags="-X main.Version=$(VERSION) -X 'main.Revision=$(Revision)' -X 'main.Time=`date`' -extldflags -static"
|
||||
GO=$(GO_ENV) $(shell which go)
|
||||
|
||||
build:
|
||||
|
|
|
@ -6,7 +6,7 @@ data:
|
|||
driver: "mysql"
|
||||
connection: root:root@tcp(db:3306)/answer
|
||||
cache:
|
||||
file_path: "/tmp/cache/cache.db"
|
||||
file_path: "/data/cache/cache.db"
|
||||
i18n:
|
||||
bundle_dir: "/data/i18n"
|
||||
swaggerui:
|
||||
|
|
2
go.mod
2
go.mod
|
@ -18,7 +18,7 @@ require (
|
|||
github.com/jinzhu/copier v0.3.5
|
||||
github.com/jinzhu/now v1.1.5
|
||||
github.com/lib/pq v1.10.2
|
||||
github.com/mattn/go-sqlite3 v2.0.3+incompatible
|
||||
github.com/mattn/go-sqlite3 v1.14.15
|
||||
github.com/mojocn/base64Captcha v1.3.5
|
||||
github.com/segmentfault/pacman v1.0.1
|
||||
github.com/segmentfault/pacman/contrib/cache/memory v0.0.0-20220929065758-260b3093a347
|
||||
|
|
4
go.sum
4
go.sum
|
@ -424,8 +424,8 @@ github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/
|
|||
github.com/mattn/go-runewidth v0.0.2/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU=
|
||||
github.com/mattn/go-sqlite3 v1.10.0/go.mod h1:FPy6KqzDD04eiIsT53CuJW3U88zkxoIYsOqkbpncsNc=
|
||||
github.com/mattn/go-sqlite3 v1.14.9/go.mod h1:NyWgC/yNuGj7Q9rpYnZvas74GogHl5/Z4A/KQRfk6bU=
|
||||
github.com/mattn/go-sqlite3 v2.0.3+incompatible h1:gXHsfypPkaMZrKbD5209QV9jbUTJKjyR5WD3HYQSd+U=
|
||||
github.com/mattn/go-sqlite3 v2.0.3+incompatible/go.mod h1:FPy6KqzDD04eiIsT53CuJW3U88zkxoIYsOqkbpncsNc=
|
||||
github.com/mattn/go-sqlite3 v1.14.15 h1:vfoHhTN1af61xCRSWzFIWzx2YskyMTwHLrExkBOjvxI=
|
||||
github.com/mattn/go-sqlite3 v1.14.15/go.mod h1:2eHXhiwb8IkHr+BDWZGa96P6+rkvnG63S2DGjv9HUNg=
|
||||
github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0=
|
||||
github.com/miekg/dns v1.0.14/go.mod h1:W1PPwlIAgtquWBMBEV9nkV9Cazfe8ScdGz/Lj7v3Nrg=
|
||||
github.com/mitchellh/cli v1.0.0/go.mod h1:hNIlj7HEI86fIcpObd7a0FcrxTWetlwJDGcceTlRvqc=
|
||||
|
|
|
@ -1,8 +1,10 @@
|
|||
package data
|
||||
|
||||
import (
|
||||
"path/filepath"
|
||||
"time"
|
||||
|
||||
"github.com/answerdev/answer/pkg/dir"
|
||||
_ "github.com/go-sql-driver/mysql"
|
||||
_ "github.com/lib/pq"
|
||||
_ "github.com/mattn/go-sqlite3"
|
||||
|
@ -69,6 +71,12 @@ func NewCache(c *CacheConf) (cache.Cache, func(), error) {
|
|||
memCache := memory.NewCache()
|
||||
|
||||
if len(c.FilePath) > 0 {
|
||||
cacheFileDir := filepath.Dir(c.FilePath)
|
||||
log.Debugf("try to create cache directory %s", cacheFileDir)
|
||||
err := dir.CreateDirIfNotExist(cacheFileDir)
|
||||
if err != nil {
|
||||
log.Errorf("create cache dir failed: %s", err)
|
||||
}
|
||||
log.Infof("try to load cache file from %s", c.FilePath)
|
||||
if err := memory.Load(memCache, c.FilePath); err != nil {
|
||||
log.Warn(err)
|
||||
|
|
Loading…
Reference in New Issue