From f91c69e26ebf42608b2a412052d38b6f890efcb6 Mon Sep 17 00:00:00 2001
From: Florian Wilhelm <florian.wilhelm02@sap.com>
Date: Wed, 18 Sep 2024 13:42:18 +0200
Subject: [PATCH 1/2] pg init container

---
 .github/workflows/pg-init.yaml | 50 ++++++++++++++++++++++++++++++++++
 Containerfile.pg-init          | 14 ++++++++++
 pg-init-entrypoint.sh          |  8 ++++++
 3 files changed, 72 insertions(+)
 create mode 100644 .github/workflows/pg-init.yaml
 create mode 100644 Containerfile.pg-init
 create mode 100755 pg-init-entrypoint.sh

diff --git a/.github/workflows/pg-init.yaml b/.github/workflows/pg-init.yaml
new file mode 100644
index 0000000..f608ce6
--- /dev/null
+++ b/.github/workflows/pg-init.yaml
@@ -0,0 +1,50 @@
+name: pg init container
+
+on:
+  workflow_dispatch:
+  pull_request:
+  push:
+    branches:
+    - main
+
+permissions:
+  # Checkout repository
+  contents: read
+  # Push container images
+  packages: write
+
+jobs:
+  build:
+    runs-on: ubuntu-24.04
+    env:
+      IMAGE_NAME: gardenlinux/glvd-postgres-init
+      IMAGE_TAG: latest
+    steps:
+    - name: Checkout repo
+      uses: actions/checkout@v4
+    - name: Install qemu dependency for multi-arch build
+      run: |
+        sudo apt-get update
+        sudo apt-get install -y qemu-user-static
+    - run: |
+        gh run download 10905326712 -n glvd.sql --repo gardenlinux/glvd-contrib
+    - name: Build Image
+      id: build_image
+      uses: redhat-actions/buildah-build@v2
+      with:
+        image: ${{ env.IMAGE_NAME }}
+        tags: ${{ env.IMAGE_TAG }}
+        platforms: linux/amd64, linux/arm64
+        containerfiles: |
+          ./Containerfile.pg-init
+
+    - name: Push To ghcr.io
+      id: push-to-ghcr
+      if: ${{ github.event_name != 'pull_request' }}
+      uses: redhat-actions/push-to-registry@v2
+      with:
+        image: ${{ steps.build_image.outputs.image }}
+        tags: ${{ steps.build_image.outputs.tags }}
+        registry: ghcr.io
+        username: ${{ github.actor }}
+        password: ${{ secrets.GITHUB_TOKEN }}
diff --git a/Containerfile.pg-init b/Containerfile.pg-init
new file mode 100644
index 0000000..1cb6691
--- /dev/null
+++ b/Containerfile.pg-init
@@ -0,0 +1,14 @@
+FROM debian
+
+ENV PGHOST glvd
+ENV PGPORT 5432
+ENV PGDATABASE glvd
+ENV PGUSER glvd
+ENV PGPASSWORD glvd
+
+RUN apt-get update && apt-get install -y postgresql-client
+
+COPY glvd.sql /glvd.sql
+COPY pg-init-entrypoint.sh /entrypoint.sh
+
+ENTRYPOINT ["/entrypoint.sh"]
diff --git a/pg-init-entrypoint.sh b/pg-init-entrypoint.sh
new file mode 100755
index 0000000..d4b901f
--- /dev/null
+++ b/pg-init-entrypoint.sh
@@ -0,0 +1,8 @@
+#!/bin/bash
+set -euo pipefail
+
+echo "$PGHOST:$PGPORT:$PGDATABASE:$PGUSER:$PGPASSWORD" > ~/.pgpass
+chmod 0600 ~/.pgpass
+
+dropdb glvd
+psql glvd -f /glvd.sql

From 8dceab98808d9d535ebb549e7e91ee6a0ad0426a Mon Sep 17 00:00:00 2001
From: Florian Wilhelm <florian.wilhelm02@sap.com>
Date: Wed, 18 Sep 2024 13:45:14 +0200
Subject: [PATCH 2/2] token

---
 .github/workflows/pg-init.yaml | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/.github/workflows/pg-init.yaml b/.github/workflows/pg-init.yaml
index f608ce6..daad352 100644
--- a/.github/workflows/pg-init.yaml
+++ b/.github/workflows/pg-init.yaml
@@ -28,6 +28,8 @@ jobs:
         sudo apt-get install -y qemu-user-static
     - run: |
         gh run download 10905326712 -n glvd.sql --repo gardenlinux/glvd-contrib
+      env:
+        GH_TOKEN: ${{ github.token }}
     - name: Build Image
       id: build_image
       uses: redhat-actions/buildah-build@v2