Skip to content

Commit

Permalink
Add tests to image build process
Browse files Browse the repository at this point in the history
Signed-off-by: eternal-flame-AD <yume@yumechi.jp>
  • Loading branch information
eternal-flame-AD committed Oct 15, 2024
1 parent 7c17433 commit decd463
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 9 deletions.
20 changes: 14 additions & 6 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ARG DEBIAN=stable
ARG DEBIAN=stable-slim

# --- JS Builder ---

Expand Down Expand Up @@ -38,6 +38,7 @@ RUN if [ "$BUILD_JS" = "1" ]; then \
FROM debian:${DEBIAN} AS builder

ARG BUILD_JS=1
ARG RUN_TESTS=1
ARG GO_BUILD_FLAGS=-mod=readonly -a -installsuffix cgo
ENV DEBIAN_FRONTEND=noninteractive

Expand All @@ -63,21 +64,28 @@ RUN cd /src/gotify && \
echo "Using Go version: $GIMME_GO_VERSION" && \
gimme ${GIMME_GO_VERSION} && \
mkdir -p /target/app && \
bash -c ". ~/.gimme/envs/go${GIMME_GO_VERSION}.env && go build ${GO_BUILD_FLAGS} -o /target/app/gotify-app"
bash -c ". ~/.gimme/envs/go${GIMME_GO_VERSION}.env && go test -v ./... && go build ${GO_BUILD_FLAGS} -o /target/app/gotify-app"

FROM debian:${DEBIAN}-slim
FROM debian:${DEBIAN}

# build-time configurable port
# build-time configurables
ARG GOTIFY_SERVER_EXPOSE=80
ARG GOTIFY_UID=0
ENV GOTIFY_SERVER_PORT=$GOTIFY_SERVER_EXPOSE

WORKDIR /app

RUN export DEBIAN_FRONTEND=noninteractive && apt-get update && apt-get install -yq --no-install-recommends \
tzdata \
curl \
ca-certificates \
&& rm -rf /var/lib/apt/lists/*
ca-certificates && \
rm -rf /var/lib/apt/lists/* && \
if [ "$GOTIFY_UID" != "0" ]; then \
useradd -u $GOTIFY_UID -r gotify && \
chown gotify:gotify /app; \
fi

USER $GOTIFY_UID

HEALTHCHECK --interval=30s --timeout=5s --start-period=5s CMD curl --fail http://localhost:$GOTIFY_SERVER_PORT/health || exit 1
EXPOSE $GOTIFY_SERVER_EXPOSE
Expand Down
8 changes: 5 additions & 3 deletions test/filepath_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,11 @@ func TestWithWd(t *testing.T) {
})

assert.Nil(t, os.Mkdir(tmpDir.Path(), 0o644))
assert.Panics(t, func() {
WithWd(tmpDir.Path(), func(string) {})
})
if os.Getuid() != 0 { // root is not subject to this check
assert.Panics(t, func() {
WithWd(tmpDir.Path(), func(string) {})
})
}
assert.Nil(t, os.Remove(tmpDir.Path()))

assert.Nil(t, os.Mkdir(tmpDir.Path(), 0o755))
Expand Down

0 comments on commit decd463

Please sign in to comment.