Better Dockerfile (#645)

* Add support for docker compose build
* Avoid copying more file than needed
* Reduce Docker image size
This commit is contained in:
Francesco Frassinelli 2023-04-01 01:55:59 +02:00 committed by GitHub
parent 08bbb1537e
commit e905e5de53
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 15 deletions

View File

@ -4,31 +4,36 @@
FROM golang:1.19-bullseye AS build
WORKDIR /build
ADD . /build
RUN git config --global --add safe.directory /build
COPY go.mod go.sum ./
RUN go mod download
COPY Makefile main.go ./
COPY static/ static/
COPY pkg/ pkg/
COPY .git/ .
RUN make build
# ------------------------------------------------------------------------------
# Fetch signing key
# ------------------------------------------------------------------------------
FROM debian:bullseye-slim AS keyring
ADD https://www.postgresql.org/media/keys/ACCC4CF8.asc keyring.asc
RUN apt-get update && \
apt-get install -qq --no-install-recommends gpg
RUN gpg -o keyring.pgp --dearmor keyring.asc
# ------------------------------------------------------------------------------
# Release Stage
# ------------------------------------------------------------------------------
FROM debian:bullseye-slim
RUN \
apt-get update && \
apt-get install -y ca-certificates openssl netcat curl gnupg lsb-release && \
update-ca-certificates
RUN \
curl --silent https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add && \
echo "deb http://apt.postgresql.org/pub/repos/apt/ `lsb_release -cs`-pgdg main" | tee /etc/apt/sources.list.d/pgdg.list && \
apt-get update && apt-get install -y postgresql-client
RUN \
apt-get clean autoclean && \
apt-get autoremove --yes && \
rm -rf /var/lib/{apt,dpkg,cache,log}/
ARG keyring=/usr/share/keyrings/postgresql-archive-keyring.pgp
COPY --from=keyring /keyring.pgp $keyring
RUN . /etc/os-release && \
echo "deb [signed-by=${keyring}] http://apt.postgresql.org/pub/repos/apt/ ${VERSION_CODENAME}-pgdg main" > /etc/apt/sources.list.d/pgdg.list && \
apt-get update && \
apt-get install -qq --no-install-recommends ca-certificates openssl netcat curl postgresql-client
COPY --from=build /build/pgweb /usr/bin/pgweb

View File

@ -22,6 +22,7 @@ services:
pgweb:
container_name: pgweb
image: sosedoff/pgweb:latest
build: .
environment:
PGWEB_DATABASE_URL: postgres://pgweb:pgweb@pgweb-postgres:5432/pgweb?sslmode=disable
ports: