Skip to content

Commit

Permalink
Docker: fix embedded image (No impact on project)
Browse files Browse the repository at this point in the history
  • Loading branch information
simonesestito committed Jan 18, 2023
1 parent dae6aec commit 4a07839
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 17 deletions.
33 changes: 18 additions & 15 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,12 @@ COPY webui .
### Compile frontend
RUN npm run build-embed

#################

FROM golang:1.19.4-alpine3.17 AS builder

### Install gcc in order to be able to use CGO later
### and ca-certificates in order to be able to perform HTTPS requests
RUN apk add --no-cache build-base ca-certificates && \
update-ca-certificates

### Create "appuser" standard user, later used in final image to run ./cmd/webapi as non-root
RUN adduser \
--home /app/ \
--disabled-password \
--shell /bin/false \
appuser
RUN apk add --no-cache build-base

### Copy Go code, copying required folders only (use .dockerignore)
WORKDIR /src/
Expand All @@ -45,23 +37,34 @@ RUN CGO_ENABLED=1 \
./cmd/webapi \
&& strip /app/*

#############################

### Create final container from scratch
FROM scratch
FROM alpine:3.17

### Inform Docker about which port is used
EXPOSE 3000

### Copy the CA Certificates in order to run HTTPS requests
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
### Install the CA Certificates in order to run HTTPS requests
RUN apk add --no-cache ca-certificates && \
update-ca-certificates

### Copy the "appuser" standard user from the build stage
COPY --from=builder /etc/passwd /etc/passwd
### Create the "appuser" standard user
RUN adduser \
--home /app/ \
--disabled-password \
--shell /bin/false \
appuser
USER appuser

### Copy the build executable from the builder image
WORKDIR /app/
COPY --from=builder /app/* ./

### Create appropriate volume
ENV CFG_DB_FILENAME=/app/db/wasaphoto.db
ENV CFG_USER_CONTENT_DIR=/app/static/user_content
RUN mkdir -p /app/db /app/static/user_content

### Executable command
CMD ["/app/webapi"]
2 changes: 0 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ services:
ports:
- '${DOCKER_HOST_PROXY_PORT:-3000}:3000'
environment:
- 'CFG_DB_FILENAME=/app/db/wasaphoto.db'
- 'CFG_USER_CONTENT_DIR=/app/static/user_content'
- 'CFG_LOG_DEBUG=false'
volumes:
- 'database:/app/db'
Expand Down

0 comments on commit 4a07839

Please sign in to comment.