1
0

add: Dockerfile for Postgres image & GitHub workflow

This commit is contained in:
alikia2x (寒寒) 2026-01-13 04:20:03 +08:00
parent 368c049255
commit 5a9e29ba50
WARNING! Although there is a key with this ID in the database it does not verify this commit! This commit is SUSPICIOUS.
GPG Key ID: 56209E0CCD8420C6
5 changed files with 183 additions and 13 deletions

112
.github/workflows/pg-image-build.yml vendored Normal file
View File

@ -0,0 +1,112 @@
name: Build the Postgres image
on:
workflow_dispatch
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}/cvsa-pg
jobs:
build:
runs-on: ${{ matrix.runner }}
permissions:
packages: write
strategy:
fail-fast: false
matrix:
include:
- arch: amd64
platform: linux/amd64
runner: ubuntu-latest
- arch: arm64
platform: linux/arm64
runner: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
flavor: |
suffix=-${{ matrix.arch }},onlatest=true
tags: |
type=raw,value=latest,enable={{is_default_branch}}
- name: Login GHCR
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
with:
driver-opts: |
image=moby/buildkit:latest
network=host
- name: Build & Push single platform
id: build
uses: docker/build-push-action@v6
with:
context: .
file: ./Dockerfile.pg
platforms: ${{ matrix.platform }}
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
outputs: type=image,name=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }},push-by-digest=true,name-canonical=true,push=true
cache-from: type=gha
cache-to: type=gha,mode=max
- name: Export digest
run: echo "${{ steps.build.outputs.digest }}" > /tmp/digest-${{ matrix.arch }}
- name: Upload digest artifact
uses: actions/upload-artifact@v4
with:
name: digest-${{ matrix.arch }}
path: /tmp/digest-${{ matrix.arch }}
if-no-files-found: error
create-manifest:
needs: build
if: github.event_name != 'pull_request'
runs-on: ubuntu-latest
permissions:
packages: write
steps:
- uses: actions/checkout@v4
- name: Login GHCR
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Download all digests
uses: actions/download-artifact@v4
with:
pattern: digest-*
path: digests
merge-multiple: true
- name: Create multi-arch manifest
run: |
docker buildx imagetools create \
--tag ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest \
--tag ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ github.sha }} \
$(cat digests/digest-amd64) \
$(cat digests/digest-arm64)

6
.gitignore vendored
View File

@ -35,7 +35,7 @@ __pycache__
/data
/redis
# Build
# Build
dist/
build/
@ -47,4 +47,6 @@ mutagen.yml
mutagen.yml.lock
.turbo
.turbo
docker-compose.yml

3
.idea/.gitignore vendored
View File

@ -7,4 +7,5 @@
/dataSources/
/dataSources.local.xml
dataSources.xml
MarsCodeWorkspaceAppSettings.xml
MarsCodeWorkspaceAppSettings.xml
data_source_mapping.xml

View File

@ -9,17 +9,7 @@
<file url="file://$PROJECT_DIR$/src/importSnapshots.ts" value="0d2dd3d3-bd27-4e5f-b0fa-ff14fb2a6bef" />
<file url="file://$APPLICATION_CONFIG_DIR$/consoles/db/0d2dd3d3-bd27-4e5f-b0fa-ff14fb2a6bef/console.sql" value="0d2dd3d3-bd27-4e5f-b0fa-ff14fb2a6bef" />
<file url="file://$APPLICATION_CONFIG_DIR$/consoles/db/0d2dd3d3-bd27-4e5f-b0fa-ff14fb2a6bef/console_1.sql" value="0d2dd3d3-bd27-4e5f-b0fa-ff14fb2a6bef" />
<file url="file://$APPLICATION_CONFIG_DIR$/consoles/db/0d2dd3d3-bd27-4e5f-b0fa-ff14fb2a6bef/console_10.sql" value="0d2dd3d3-bd27-4e5f-b0fa-ff14fb2a6bef" />
<file url="file://$APPLICATION_CONFIG_DIR$/consoles/db/0d2dd3d3-bd27-4e5f-b0fa-ff14fb2a6bef/console_3.sql" value="0d2dd3d3-bd27-4e5f-b0fa-ff14fb2a6bef" />
<file url="file://$APPLICATION_CONFIG_DIR$/consoles/db/0d2dd3d3-bd27-4e5f-b0fa-ff14fb2a6bef/console_4.sql" value="0d2dd3d3-bd27-4e5f-b0fa-ff14fb2a6bef" />
<file url="file://$APPLICATION_CONFIG_DIR$/consoles/db/0d2dd3d3-bd27-4e5f-b0fa-ff14fb2a6bef/console_5.sql" value="0d2dd3d3-bd27-4e5f-b0fa-ff14fb2a6bef" />
<file url="file://$APPLICATION_CONFIG_DIR$/consoles/db/0d2dd3d3-bd27-4e5f-b0fa-ff14fb2a6bef/console_6.sql" value="0d2dd3d3-bd27-4e5f-b0fa-ff14fb2a6bef" />
<file url="file://$APPLICATION_CONFIG_DIR$/consoles/db/0d2dd3d3-bd27-4e5f-b0fa-ff14fb2a6bef/console_7.sql" value="0d2dd3d3-bd27-4e5f-b0fa-ff14fb2a6bef" />
<file url="file://$APPLICATION_CONFIG_DIR$/consoles/db/0d2dd3d3-bd27-4e5f-b0fa-ff14fb2a6bef/console_8.sql" value="0d2dd3d3-bd27-4e5f-b0fa-ff14fb2a6bef" />
<file url="file://$APPLICATION_CONFIG_DIR$/consoles/db/0d2dd3d3-bd27-4e5f-b0fa-ff14fb2a6bef/console_9.sql" value="0d2dd3d3-bd27-4e5f-b0fa-ff14fb2a6bef" />
<file url="file://$APPLICATION_CONFIG_DIR$/consoles/db/360f07a5-22e0-4aa5-8453-7b7e913f2fc7/console.sql" value="360f07a5-22e0-4aa5-8453-7b7e913f2fc7" />
<file url="file://$APPLICATION_CONFIG_DIR$/consoles/db/3909a3cf-ec53-4749-8a31-9f90fec87ee1/console_1.sql" value="3909a3cf-ec53-4749-8a31-9f90fec87ee1" />
<file url="file://$APPLICATION_CONFIG_DIR$/consoles/db/3909a3cf-ec53-4749-8a31-9f90fec87ee1/console_2.sql" value="3909a3cf-ec53-4749-8a31-9f90fec87ee1" />
<file url="file://$APPLICATION_CONFIG_DIR$/consoles/db/c73d5a8a-cf9a-4e08-bc75-84af9a6f1ba9/console.sql" value="c73d5a8a-cf9a-4e08-bc75-84af9a6f1ba9" />
</component>
</project>

65
Dockerfile.pg Normal file
View File

@ -0,0 +1,65 @@
FROM postgres:18.1
RUN localedef -i zh_CN -c -f UTF-8 -A /usr/share/locale/locale.alias zh_CN.UTF-8
ENV LANG=zh_CN.utf8 LC_ALL=zh_CN.utf8
LABEL maintainer="alikia2x <alikia2x@outlook.com>" \
description="Customized PostgreSQL image for Project CVSA including TimescaleDB & pgBackRest" \
version="1.0.0" \
org.opencontainers.image.title="CVSA PostgreSQL Extended" \
org.opencontainers.image.description="Customized PostgreSQL image for Project CVSA including TimescaleDB & pgBackRest" \
org.opencontainers.image.vendor="Luminara Studio" \
org.opencontainers.image.version="1.0.0" \
org.opencontainers.image.authors="alikia2x@outlook.com"
ENV DEBIAN_FRONTEND=noninteractive \
TZ=Asia/Shanghai
USER root
RUN set -eux; \
apt update -qq; \
apt install -y --no-install-recommends \
ca-certificates \
curl \
gnupg \
lsb-release \
wget \
; \
curl -fsSL https://www.postgresql.org/media/keys/ACCC4CF8.asc | gpg --dearmor -o /etc/apt/trusted.gpg.d/apt.postgresql.org.gpg; \
echo "deb https://apt.postgresql.org/pub/repos/apt/ $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list; \
\
curl -L https://packagecloud.io/timescale/timescaledb/gpgkey | gpg --dearmor -o /etc/apt/trusted.gpg.d/timescaledb.gpg; \
echo "deb https://packagecloud.io/timescale/timescaledb/debian/ $(lsb_release -cs) main" > /etc/apt/sources.list.d/timescaledb.list; \
\
wget https://packages.groonga.org/debian/groonga-apt-source-latest-$(lsb_release --codename --short).deb; \
apt install -y -V ./groonga-apt-source-latest-$(lsb_release --codename --short).deb; \
\
apt update -q;
RUN apt install -y -V \
timescaledb-2-postgresql-18 \
postgresql-18-pgvector \
postgresql-18-cron \
postgresql-18-repack \
pgbackrest \
;
RUN apt purge -y --auto-remove \
curl gnupg lsb-release wget \
&& apt clean \
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
RUN mkdir -p /etc/postgresql/custom
RUN cp /usr/share/postgresql/postgresql.conf.sample /etc/postgresql/postgresql.conf
RUN echo "include_dir = '/etc/postgresql/custom/'" >> /etc/postgresql/postgresql.conf
RUN echo "shared_preload_libraries = 'timescaledb,pg_cron,pg_stat_statements'" >> /etc/postgresql/custom/extensions.conf
USER postgres
EXPOSE 5432
HEALTHCHECK --interval=20s --timeout=10s --start-period=5s --retries=3 \
CMD pg_isready -U postgres -h 127.0.0.1 || exit 1
CMD ["postgres"]