From 7e2de57b0cbb922a2a0c2964934a51d977043192 Mon Sep 17 00:00:00 2001 From: "Yuito Akatsuki (Tani Yutaka)" Date: Sat, 22 Aug 2026 10:46:23 +0900 Subject: [PATCH 1/6] =?UTF-8?q?feat:=20PostgreSQL=E3=81=AE=E3=83=AA?= =?UTF-8?q?=E3=82=BD=E3=83=BC=E3=82=B9=E5=88=B6=E9=99=90=E3=81=A8=E8=A6=81?= =?UTF-8?q?=E6=B1=82=E3=82=92=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Yuito Akatsuki (Tani Yutaka) --- argoCD/overlays/sub/postgresql.yaml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/argoCD/overlays/sub/postgresql.yaml b/argoCD/overlays/sub/postgresql.yaml index 1aaa7eaa..f77c24d7 100644 --- a/argoCD/overlays/sub/postgresql.yaml +++ b/argoCD/overlays/sub/postgresql.yaml @@ -26,6 +26,13 @@ spec: volumeMounts: - name: postgre-storage mountPath: /var/lib/postgresql + resources: + requests: + cpu: 100Mi + memory: 256Mi + limits: + cpu: 500Mi + memory: 512Mi volumes: - name: postgre-storage persistentVolumeClaim: From b7cf542443039da9a6fcae439963ddd1687974a7 Mon Sep 17 00:00:00 2001 From: "Yuito Akatsuki (Tani Yutaka)" Date: Sat, 22 Aug 2026 10:47:23 +0900 Subject: [PATCH 2/6] =?UTF-8?q?fix:=20CPU=E3=83=AA=E3=82=BD=E3=83=BC?= =?UTF-8?q?=E3=82=B9=E3=81=AE=E5=8D=98=E4=BD=8D=E3=82=92=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Yuito Akatsuki (Tani Yutaka) --- argoCD/overlays/sub/postgresql.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/argoCD/overlays/sub/postgresql.yaml b/argoCD/overlays/sub/postgresql.yaml index f77c24d7..aa628b7f 100644 --- a/argoCD/overlays/sub/postgresql.yaml +++ b/argoCD/overlays/sub/postgresql.yaml @@ -28,10 +28,10 @@ spec: mountPath: /var/lib/postgresql resources: requests: - cpu: 100Mi + cpu: 100m memory: 256Mi limits: - cpu: 500Mi + cpu: 500m memory: 512Mi volumes: - name: postgre-storage From 2fd7051d73e2176df5d6bf95c890e3a3776a1c97 Mon Sep 17 00:00:00 2001 From: "Yuito Akatsuki (Tani Yutaka)" Date: Sat, 22 Aug 2026 11:12:45 +0900 Subject: [PATCH 3/6] =?UTF-8?q?feat:=20=E3=83=87=E3=83=BC=E3=82=BF?= =?UTF-8?q?=E3=83=99=E3=83=BC=E3=82=B9=E3=82=B9=E3=82=AD=E3=83=BC=E3=83=9E?= =?UTF-8?q?=E3=81=A8=E3=83=9E=E3=82=A4=E3=82=B0=E3=83=AC=E3=83=BC=E3=82=B7?= =?UTF-8?q?=E3=83=A7=E3=83=B3=E3=83=95=E3=82=A1=E3=82=A4=E3=83=AB=E3=82=92?= =?UTF-8?q?=E7=A7=BB=E5=8B=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Yuito Akatsuki (Tani Yutaka) --- Makefile | 12 ++++++------ atlas.hcl => db/atlas.hcl | 0 {migrations => db/migrations}/20260805041044.sql | 0 {migrations => db/migrations}/20260820085802.sql | 0 {migrations => db/migrations}/atlas.sum | 0 {schema => db/schema}/all_schemas.pg.hcl | 0 {schema => db/schema}/channels.pg.hcl | 0 {schema => db/schema}/functions.pg.hcl | 0 {schema => db/schema}/guilds.pg.hcl | 0 {schema => db/schema}/members.pg.hcl | 0 {schema => db/schema}/pin_settings.pg.hcl | 0 {schema => db/schema}/remind_settings.pg.hcl | 0 {schema => db/schema}/rss_settings.pg.hcl | 0 {schema => db/schema}/system_preference.pg.hcl | 0 {schema => db/schema}/tts_connections.pg.hcl | 0 {schema => db/schema}/tts_dictionary.pg.hcl | 0 {schema => db/schema}/tts_member_preference.pg.hcl | 0 {schema => db/schema}/tts_user_preference.pg.hcl | 0 {schema => db/schema}/users.pg.hcl | 0 19 files changed, 6 insertions(+), 6 deletions(-) rename atlas.hcl => db/atlas.hcl (100%) rename {migrations => db/migrations}/20260805041044.sql (100%) rename {migrations => db/migrations}/20260820085802.sql (100%) rename {migrations => db/migrations}/atlas.sum (100%) rename {schema => db/schema}/all_schemas.pg.hcl (100%) rename {schema => db/schema}/channels.pg.hcl (100%) rename {schema => db/schema}/functions.pg.hcl (100%) rename {schema => db/schema}/guilds.pg.hcl (100%) rename {schema => db/schema}/members.pg.hcl (100%) rename {schema => db/schema}/pin_settings.pg.hcl (100%) rename {schema => db/schema}/remind_settings.pg.hcl (100%) rename {schema => db/schema}/rss_settings.pg.hcl (100%) rename {schema => db/schema}/system_preference.pg.hcl (100%) rename {schema => db/schema}/tts_connections.pg.hcl (100%) rename {schema => db/schema}/tts_dictionary.pg.hcl (100%) rename {schema => db/schema}/tts_member_preference.pg.hcl (100%) rename {schema => db/schema}/tts_user_preference.pg.hcl (100%) rename {schema => db/schema}/users.pg.hcl (100%) diff --git a/Makefile b/Makefile index 78321022..eb87324a 100644 --- a/Makefile +++ b/Makefile @@ -1,17 +1,17 @@ .PHONY: migration-apply migration-diff schema-apply schema-lint migration-apply: - set -a && source .env && set +a && atlas migrate apply --env "local" + set -a && source .env && set +a && cd db && atlas migrate apply --env "local" migration-diff: - set -a && source .env && set +a && atlas migrate diff --env "local" + set -a && source .env && set +a && cd db && atlas migrate diff --env "local" migration-hash: - set -a && source .env && set +a && atlas migrate hash + set -a && source .env && set +a && cd db && atlas migrate hash schema-apply: - set -a && source .env && set +a && atlas schema apply --env "local" + set -a && source .env && set +a && cd db && atlas schema apply --env "local" schema-lint: - set -a && source .env && set +a && atlas schema lint --env "local" + set -a && source .env && set +a && cd db && atlas schema lint --env "local" db-clean: - set -a && source .env && set +a && atlas schema clean --env "local" + set -a && source .env && set +a && cd db && atlas schema clean --env "local" model-gen: set -a && source .env && set +a && cd src && go run cmd/gen/main.go && cd ../ diff --git a/atlas.hcl b/db/atlas.hcl similarity index 100% rename from atlas.hcl rename to db/atlas.hcl diff --git a/migrations/20260805041044.sql b/db/migrations/20260805041044.sql similarity index 100% rename from migrations/20260805041044.sql rename to db/migrations/20260805041044.sql diff --git a/migrations/20260820085802.sql b/db/migrations/20260820085802.sql similarity index 100% rename from migrations/20260820085802.sql rename to db/migrations/20260820085802.sql diff --git a/migrations/atlas.sum b/db/migrations/atlas.sum similarity index 100% rename from migrations/atlas.sum rename to db/migrations/atlas.sum diff --git a/schema/all_schemas.pg.hcl b/db/schema/all_schemas.pg.hcl similarity index 100% rename from schema/all_schemas.pg.hcl rename to db/schema/all_schemas.pg.hcl diff --git a/schema/channels.pg.hcl b/db/schema/channels.pg.hcl similarity index 100% rename from schema/channels.pg.hcl rename to db/schema/channels.pg.hcl diff --git a/schema/functions.pg.hcl b/db/schema/functions.pg.hcl similarity index 100% rename from schema/functions.pg.hcl rename to db/schema/functions.pg.hcl diff --git a/schema/guilds.pg.hcl b/db/schema/guilds.pg.hcl similarity index 100% rename from schema/guilds.pg.hcl rename to db/schema/guilds.pg.hcl diff --git a/schema/members.pg.hcl b/db/schema/members.pg.hcl similarity index 100% rename from schema/members.pg.hcl rename to db/schema/members.pg.hcl diff --git a/schema/pin_settings.pg.hcl b/db/schema/pin_settings.pg.hcl similarity index 100% rename from schema/pin_settings.pg.hcl rename to db/schema/pin_settings.pg.hcl diff --git a/schema/remind_settings.pg.hcl b/db/schema/remind_settings.pg.hcl similarity index 100% rename from schema/remind_settings.pg.hcl rename to db/schema/remind_settings.pg.hcl diff --git a/schema/rss_settings.pg.hcl b/db/schema/rss_settings.pg.hcl similarity index 100% rename from schema/rss_settings.pg.hcl rename to db/schema/rss_settings.pg.hcl diff --git a/schema/system_preference.pg.hcl b/db/schema/system_preference.pg.hcl similarity index 100% rename from schema/system_preference.pg.hcl rename to db/schema/system_preference.pg.hcl diff --git a/schema/tts_connections.pg.hcl b/db/schema/tts_connections.pg.hcl similarity index 100% rename from schema/tts_connections.pg.hcl rename to db/schema/tts_connections.pg.hcl diff --git a/schema/tts_dictionary.pg.hcl b/db/schema/tts_dictionary.pg.hcl similarity index 100% rename from schema/tts_dictionary.pg.hcl rename to db/schema/tts_dictionary.pg.hcl diff --git a/schema/tts_member_preference.pg.hcl b/db/schema/tts_member_preference.pg.hcl similarity index 100% rename from schema/tts_member_preference.pg.hcl rename to db/schema/tts_member_preference.pg.hcl diff --git a/schema/tts_user_preference.pg.hcl b/db/schema/tts_user_preference.pg.hcl similarity index 100% rename from schema/tts_user_preference.pg.hcl rename to db/schema/tts_user_preference.pg.hcl diff --git a/schema/users.pg.hcl b/db/schema/users.pg.hcl similarity index 100% rename from schema/users.pg.hcl rename to db/schema/users.pg.hcl From 2a607905d1f99f150ad360c848fa998f11e6ad1c Mon Sep 17 00:00:00 2001 From: "Yuito Akatsuki (Tani Yutaka)" Date: Sat, 22 Aug 2026 11:30:41 +0900 Subject: [PATCH 4/6] =?UTF-8?q?feat:=20Docker=E3=83=93=E3=83=AB=E3=83=89?= =?UTF-8?q?=E3=81=A8=E3=83=97=E3=83=83=E3=82=B7=E3=83=A5=E3=81=AE=E3=83=AF?= =?UTF-8?q?=E3=83=BC=E3=82=AF=E3=83=95=E3=83=AD=E3=83=BC=E3=82=92=E8=BF=BD?= =?UTF-8?q?=E5=8A=A0=E3=81=97=E3=80=81DB=E3=83=9E=E3=82=A4=E3=82=B0?= =?UTF-8?q?=E3=83=AC=E3=83=BC=E3=82=B7=E3=83=A7=E3=83=B3=E3=82=B8=E3=83=A7?= =?UTF-8?q?=E3=83=96=E3=82=92=E8=A8=AD=E5=AE=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Yuito Akatsuki (Tani Yutaka) --- .github/workflows/docker-tag.yaml | 56 ++++++++++++++++++++++++++++--- Dockerfile.atlas | 5 +++ argoCD/base/deployment.yaml | 23 +++++++------ argoCD/overlays/sub/atlas.yaml | 27 +++++++++++++++ db/atlas.hcl | 13 +++++++ 5 files changed, 110 insertions(+), 14 deletions(-) create mode 100644 Dockerfile.atlas create mode 100644 argoCD/overlays/sub/atlas.yaml diff --git a/.github/workflows/docker-tag.yaml b/.github/workflows/docker-tag.yaml index 1aff0058..ef899d0e 100644 --- a/.github/workflows/docker-tag.yaml +++ b/.github/workflows/docker-tag.yaml @@ -11,9 +11,60 @@ permissions: id-token: write jobs: - build: + build-atlas-image: runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@8d2750c68a42422c14e847fe6c8ac0403b4cbd6f # v3 + + - name: Login to Harbor Registry + uses: docker/login-action@5e57cd118135c172c3672efd75eb46360885c0ef # v3 + with: + registry: registry.uniproject.jp + username: robot$github-publisher + password: ${{ secrets.HARBOR_TOKEN }} + + - name: Add metadata + id: meta + uses: docker/metadata-action@c299e40c65443455700f0fdfc63efafe5b349051 # v5 + with: + images: registry.uniproject.jp/infra/unibot-atlas + tags: | + type=raw,value=latest + type=sha,prefix=sha-,suffix=,format=short + + - name: Install Cosign + uses: sigstore/cosign-installer@398d4b0eeef1380460a10c8013a76f728fb906ac # v3 + - name: Build and Push Docker image + id: build-and-push + uses: docker/build-push-action@263435318d21b8e681c14492fe198d362a7d2c83 # v6 + with: + file: ./${{ env.DOCKERFILE }} + context: . + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + cache-from: type=registry,ref=registry.uniproject.jp/infra/unibot-atlas:buildcache + cache-to: type=registry,ref=registry.uniproject.jp/infra/unibot-atlas:buildcache,mode=max + + - name: Sign Docker images with GitHub OIDC (cosign keyless) + env: + TAGS: ${{ steps.meta.outputs.tags }} + DIGEST: ${{ steps.build-and-push.outputs.digest }} + COSIGN_EXPERIMENTAL: "true" + run: | + images="" + for tag in ${TAGS}; do + images="${images}${tag}@${DIGEST} " + done + + cosign sign --yes ${images} + build-target-image: + runs-on: ubuntu-latest steps: - name: Checkout repository uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6 @@ -62,9 +113,6 @@ jobs: - name: Install Cosign uses: sigstore/cosign-installer@398d4b0eeef1380460a10c8013a76f728fb906ac # v3 - - name: Set up QEMU - uses: docker/setup-qemu-action@c7c53464625b32c7a7e944ae62b3e17d2b600130 # v3 - - name: Build and Push Docker image id: build-and-push uses: docker/build-push-action@263435318d21b8e681c14492fe198d362a7d2c83 # v6 diff --git a/Dockerfile.atlas b/Dockerfile.atlas new file mode 100644 index 00000000..f45ef8ec --- /dev/null +++ b/Dockerfile.atlas @@ -0,0 +1,5 @@ +FROM arigaio/atlas:1.3.1-distroless AS migration-prod +WORKDIR /app +COPY ./db/migrations/ /app/migrations +COPY ./db/atlas.hcl /app/atlas.hcl +CMD ["atlas", "migrate", "apply", "--env", "prod"] \ No newline at end of file diff --git a/argoCD/base/deployment.yaml b/argoCD/base/deployment.yaml index 012d326a..61c8fb0c 100644 --- a/argoCD/base/deployment.yaml +++ b/argoCD/base/deployment.yaml @@ -1,6 +1,8 @@ apiVersion: apps/v1 kind: Deployment metadata: + annotations: + argocd.argoproj.io/sync-wave: "2" name: unibot spec: selector: @@ -21,10 +23,6 @@ spec: env: - name: TZ value: Asia/Tokyo - # ロギング設定。秘密情報ではないためここで平文管理する。 - # 明示的な env は envFrom より優先されるため、下記のキーは - # Secret 側に同名の値を置いても上書きされない。 - # Secret で管理したくなった場合は、ここの定義を削除すること。 - name: CONFIG_LOG_LEVEL value: "info" - name: CONFIG_LOG_FORMAT @@ -33,11 +31,16 @@ spec: value: "warn" - name: CONFIG_LOG_DISCORD_LEVEL value: "notice" - # 未設定の間は Discord への通知が無効になるだけで、Bot は正常に動作する。 - # 運用側でチャンネル ID を設定すること。 - # - name: CONFIG_LOG_ERROR_CHANNEL_ID - # value: "" - # - name: CONFIG_LOG_READY_CHANNEL_ID - # value: "" + - name: CONFIG_LOG_READY_CHANNEL_ID + value: "1228574771856543835" + - name: CONFIG_LOG_ERROR_CHANNEL_ID + value: "1236638014919147570" + resources: + requests: + cpu: 100m + memory: 256Mi + limits: + cpu: 500m + memory: 512Mi imagePullSecrets: - name: internal-harbor diff --git a/argoCD/overlays/sub/atlas.yaml b/argoCD/overlays/sub/atlas.yaml new file mode 100644 index 00000000..f162b785 --- /dev/null +++ b/argoCD/overlays/sub/atlas.yaml @@ -0,0 +1,27 @@ +apiVersion: batch/v1 +kind: Job +metadata: + name: db-migration-job + annotations: + argocd.argoproj.io/hook: PreSync + argocd.argoproj.io/hook-delete-policy: BeforeHookCreation + argocd.argoproj.io/sync-wave: "-1" +spec: + backoffLimit: 0 + completions: 1 + parallelism: 1 + template: + spec: + restartPolicy: Never + imagePullSecrets: + - name: my-registry-secret + containers: + - name: db-migration-job + image: "registry.uniproject.jp/infra/unibot-atlas:latest" + imagePullPolicy: Always + envFrom: + - secretRef: + name: unibot-env + key: PG_DSN + imagePullSecrets: + - name: internal-harbor diff --git a/db/atlas.hcl b/db/atlas.hcl index 9f29f575..5238b29d 100644 --- a/db/atlas.hcl +++ b/db/atlas.hcl @@ -1,3 +1,8 @@ +variable "pg_dsn" { + type = string + default = getenv("PG_DSN") +} + env "local" { url = getenv("PG_DSN") dev = "docker://postgres/18/dev" @@ -7,4 +12,12 @@ env "local" { migration { dir = "file://migrations" } +} + +env "prod" { + url = var.pg_dsn + + migration { + dir = "file://migrations" + } } \ No newline at end of file From 2a35d7525027062a2d9348f8e3a736667143f8c1 Mon Sep 17 00:00:00 2001 From: "Yuito Akatsuki (Tani Yutaka)" Date: Sat, 22 Aug 2026 11:36:45 +0900 Subject: [PATCH 5/6] =?UTF-8?q?feat:=20PostgreSQL=E3=81=AEPVC=E5=90=8D?= =?UTF-8?q?=E3=82=92=E5=A4=89=E6=9B=B4=E3=81=97=E3=81=A6=E4=B8=80=E8=B2=AB?= =?UTF-8?q?=E6=80=A7=E3=82=92=E6=8C=81=E3=81=9F=E3=81=9B=E3=82=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Yuito Akatsuki (Tani Yutaka) --- argoCD/overlays/sub/postgresql.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/argoCD/overlays/sub/postgresql.yaml b/argoCD/overlays/sub/postgresql.yaml index aa628b7f..20285be7 100644 --- a/argoCD/overlays/sub/postgresql.yaml +++ b/argoCD/overlays/sub/postgresql.yaml @@ -36,7 +36,7 @@ spec: volumes: - name: postgre-storage persistentVolumeClaim: - claimName: postgre-pvc + claimName: postgre-second-pvc --- apiVersion: v1 kind: Service @@ -54,7 +54,7 @@ spec: apiVersion: v1 kind: PersistentVolumeClaim metadata: - name: postgre-pvc + name: postgre-second-pvc spec: accessModes: - ReadWriteOnce From a4a5f2457e779af1d4e782db4e70fec3e6eb3e77 Mon Sep 17 00:00:00 2001 From: "Yuito Akatsuki (Yutaka Tani)" Date: Sat, 22 Aug 2026 20:40:00 +0900 Subject: [PATCH 6/6] Update .github/workflows/docker-tag.yaml Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> Signed-off-by: Yuito Akatsuki (Yutaka Tani) --- .github/workflows/docker-tag.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/docker-tag.yaml b/.github/workflows/docker-tag.yaml index ef899d0e..f09aa542 100644 --- a/.github/workflows/docker-tag.yaml +++ b/.github/workflows/docker-tag.yaml @@ -43,7 +43,7 @@ jobs: id: build-and-push uses: docker/build-push-action@263435318d21b8e681c14492fe198d362a7d2c83 # v6 with: - file: ./${{ env.DOCKERFILE }} + file: ./Dockerfile.atlas context: . push: true tags: ${{ steps.meta.outputs.tags }}