Docker build refactor (#568)

This commit is contained in:
Dan Sosedoff 2022-06-27 22:31:57 -05:00 committed by GitHub
parent 193073727a
commit ae3b74ad2a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 148 additions and 13 deletions

View File

@ -1 +1,3 @@
*
.github
bin/
./pgweb

33
.github/workflows/build.yml vendored Normal file
View File

@ -0,0 +1,33 @@
name: build
on:
- push
env:
GO_VERSION: 1.18
CGO_ENABLED: 0
IMAGE_REPOSITORY: sosedoff/pgweb
jobs:
docker-build:
name: docker images
runs-on: ubuntu-latest
timeout-minutes: 20
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
- name: Configure docker build context
uses: docker/setup-buildx-action@v2
- name: Build docker images
uses: docker/build-push-action@v2
with:
context: .
push: false
tags: pgweb:latest
platforms: linux/amd64,linux/arm64,linux/arm/v5,linux/arm/v7

47
.github/workflows/release.yml vendored Normal file
View File

@ -0,0 +1,47 @@
name: release
on:
push:
tags:
- "v*"
env:
GO_VERSION: 1.18
CGO_ENABLED: 0
IMAGE_REPOSITORY: sosedoff/pgweb
jobs:
docker-release:
name: Publish Docker images
runs-on: ubuntu-latest
timeout-minutes: 20
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Configure docker build context
uses: docker/setup-buildx-action@v1
- name: Set reference tags
id: refs
run: |
echo ::set-output name=SOURCE_NAME::${GITHUB_REF#refs/*/}
echo ::set-output name=SOURCE_BRANCH::${GITHUB_REF#refs/heads/}
echo ::set-output name=SOURCE_TAG::${GITHUB_REF#refs/tags/v}
- name: Login to Docker
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Build and push docker images
uses: docker/build-push-action@v2
with:
context: .
push: true
tags: |
${{ env.IMAGE_REPOSITORY }}:${{ steps.refs.outputs.SOURCE_TAG }}
${{ env.IMAGE_REPOSITORY }}:latest
platforms: linux/amd64,linux/arm64,linux/arm/v5,linux/arm/v7

View File

@ -1,17 +1,29 @@
FROM alpine:3.15
LABEL maintainer="Dan Sosedoff <dan.sosedoff@gmail.com>"
ENV PGWEB_VERSION 0.11.11
# ------------------------------------------------------------------------------
# Builder Stage
# ------------------------------------------------------------------------------
FROM golang:1.18-buster AS build
WORKDIR /build
ADD . /build
RUN go mod download
RUN make build
# ------------------------------------------------------------------------------
# Release Stage
# ------------------------------------------------------------------------------
FROM debian:buster-slim
RUN \
apk update && \
apk add --no-cache ca-certificates openssl postgresql wget && \
apt-get update && \
apt-get install -y ca-certificates openssl postgresql && \
update-ca-certificates && \
rm -rf /var/cache/apk/* && \
cd /tmp && \
wget -q https://github.com/sosedoff/pgweb/releases/download/v$PGWEB_VERSION/pgweb_linux_amd64.zip && \
unzip pgweb_linux_amd64.zip -d /usr/bin && \
mv /usr/bin/pgweb_linux_amd64 /usr/bin/pgweb && \
rm -f pgweb_linux_amd64.zip
apt-get clean autoclean && \
apt-get autoremove --yes && \
rm -rf /var/lib/{apt,dpkg,cache,log}/
COPY --from=build /build/pgweb /usr/bin/pgweb
EXPOSE 8081
CMD ["/usr/bin/pgweb", "--bind=0.0.0.0", "--listen=8081"]

View File

@ -1,4 +1,4 @@
TARGETS = darwin/amd64 darwin/arm64 linux/amd64 linux/386 windows/amd64 windows/386
TARGETS = darwin/amd64 darwin/arm64 linux/amd64 linux/arm64 windows/amd64
GIT_COMMIT = $(shell git rev-parse HEAD)
BUILD_TIME = $(shell date -u +"%Y-%m-%dT%H:%M:%SZ" | tr -d '\n')
GO_VERSION = $(shell go version | awk {'print $$3'})

41
docker-compose.yml Normal file
View File

@ -0,0 +1,41 @@
---
version: "3.9"
services:
postgres:
container_name: pgweb-postgres
image: postgres:14
ports:
- 5433:5432
volumes:
- data:/var/lib/postgresql/data
environment:
POSTGRES_DB: pgweb
POSTGRES_PASSWORD: pgweb
POSTGRES_USER: pgweb
healthcheck:
test: pg_isready -U pgweb -h 127.0.0.1
interval: 5s
networks:
- pgweb
pgweb:
container_name: pgweb
image: sosedoff/pgweb:latest
environment:
DATABASE_URL: postgres://pgweb:pgweb@pgweb-postgres:5432/pgweb?sslmode=disable
ports:
- 8081:8081
networks:
- pgweb
depends_on:
postgres:
condition: service_healthy
volumes:
data:
name: pgweb_postgres
networks:
pgweb:
name: pgweb