Docker build refactor (#568)
This commit is contained in:
parent
193073727a
commit
ae3b74ad2a
@ -1 +1,3 @@
|
|||||||
*
|
.github
|
||||||
|
bin/
|
||||||
|
./pgweb
|
||||||
|
33
.github/workflows/build.yml
vendored
Normal file
33
.github/workflows/build.yml
vendored
Normal 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
47
.github/workflows/release.yml
vendored
Normal 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
|
34
Dockerfile
34
Dockerfile
@ -1,17 +1,29 @@
|
|||||||
FROM alpine:3.15
|
# ------------------------------------------------------------------------------
|
||||||
LABEL maintainer="Dan Sosedoff <dan.sosedoff@gmail.com>"
|
# Builder Stage
|
||||||
ENV PGWEB_VERSION 0.11.11
|
# ------------------------------------------------------------------------------
|
||||||
|
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 \
|
RUN \
|
||||||
apk update && \
|
apt-get update && \
|
||||||
apk add --no-cache ca-certificates openssl postgresql wget && \
|
apt-get install -y ca-certificates openssl postgresql && \
|
||||||
update-ca-certificates && \
|
update-ca-certificates && \
|
||||||
rm -rf /var/cache/apk/* && \
|
apt-get clean autoclean && \
|
||||||
cd /tmp && \
|
apt-get autoremove --yes && \
|
||||||
wget -q https://github.com/sosedoff/pgweb/releases/download/v$PGWEB_VERSION/pgweb_linux_amd64.zip && \
|
rm -rf /var/lib/{apt,dpkg,cache,log}/
|
||||||
unzip pgweb_linux_amd64.zip -d /usr/bin && \
|
|
||||||
mv /usr/bin/pgweb_linux_amd64 /usr/bin/pgweb && \
|
COPY --from=build /build/pgweb /usr/bin/pgweb
|
||||||
rm -f pgweb_linux_amd64.zip
|
|
||||||
|
|
||||||
EXPOSE 8081
|
EXPOSE 8081
|
||||||
|
|
||||||
CMD ["/usr/bin/pgweb", "--bind=0.0.0.0", "--listen=8081"]
|
CMD ["/usr/bin/pgweb", "--bind=0.0.0.0", "--listen=8081"]
|
||||||
|
2
Makefile
2
Makefile
@ -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)
|
GIT_COMMIT = $(shell git rev-parse HEAD)
|
||||||
BUILD_TIME = $(shell date -u +"%Y-%m-%dT%H:%M:%SZ" | tr -d '\n')
|
BUILD_TIME = $(shell date -u +"%Y-%m-%dT%H:%M:%SZ" | tr -d '\n')
|
||||||
GO_VERSION = $(shell go version | awk {'print $$3'})
|
GO_VERSION = $(shell go version | awk {'print $$3'})
|
||||||
|
41
docker-compose.yml
Normal file
41
docker-compose.yml
Normal 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
|
Loading…
x
Reference in New Issue
Block a user