+6
.env.example
+6
.env.example
+1
.gitattributes
+1
.gitattributes
···
1
+
*.sh text eol=lf
+21
-6
Dockerfile
+21
-6
Dockerfile
···
16
16
COPY . /app
17
17
18
18
RUN go mod download
19
-
RUN mkdir data
20
-
RUN mkdir data/docs
21
19
22
-
RUN CGO_ENABLED=0 GOOS=linux go build -o /space
20
+
ENV CGO_ENABLED=0
21
+
ENV GOOS=linux
22
+
RUN go build -ldflags '-s -w -extldflags "-static"' -tags osusergo,netgo,sqlite_omit_load_extension -o /space
23
23
24
-
FROM scratch
24
+
ADD https://github.com/benbjohnson/litestream/releases/download/v0.3.13/litestream-v0.3.13-linux-amd64.tar.gz /tmp/litestream.tar.gz
25
+
RUN tar -C /usr/local/bin -xzf /tmp/litestream.tar.gz
26
+
27
+
FROM alpine
25
28
WORKDIR /
29
+
26
30
COPY --from=build-styles /app/static /static
27
-
COPY --from=build-server /app/data /data
28
31
COPY --from=build-server /space /space
32
+
COPY --from=build-server /usr/local/bin/litestream /usr/local/bin/litestream
33
+
34
+
RUN apk add bash
35
+
RUN mkdir -p /data
36
+
37
+
COPY etc/litestream.yml /etc/litestream.yml
38
+
COPY scripts/run.sh /scripts/run.sh
39
+
29
40
EXPOSE 80
30
-
ENTRYPOINT ["/space"]
41
+
42
+
COPY etc/litestream.yml /etc/litestream.yml
43
+
COPY scripts/run.sh /scripts/run.sh
44
+
45
+
CMD [ "/scripts/run.sh" ]
+9
etc/litestream.yml
+9
etc/litestream.yml
+15
scripts/run.sh
+15
scripts/run.sh
···
1
+
#!/bin/bash
2
+
set -e
3
+
4
+
echo "Starting script"
5
+
6
+
# Restore the database if it does not already exist.
7
+
if [ -f /data/data.db ]; then
8
+
echo "Database already exists, skipping restore"
9
+
else
10
+
echo "No database found, restoring from replica if exists"
11
+
litestream restore -if-replica-exists /data/data.db
12
+
fi
13
+
14
+
# Run litestream with your app as the subprocess.
15
+
exec litestream replicate -exec "/space"