-
Notifications
You must be signed in to change notification settings - Fork 1
feat/mitomen/261/CI-CD-Pipeline #262
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Changes from all commits
17b3193
a905492
7c53aee
bcab84b
a6aecbb
3acc9ad
e799944
8d256a0
196cfc8
766ee94
ac32349
c95100f
0e23719
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| name: CD | ||
|
|
||
| on: | ||
| workflow_call: | ||
| workflow_dispatch: | ||
|
|
||
| jobs: | ||
| deploy: | ||
| runs-on: self-hosted | ||
| steps: | ||
| - name: Add deploy host key | ||
| run: | | ||
| mkdir -p ~/.ssh | ||
| ssh-keygen -R "${{ secrets.CONTAINER_IP }}" 2>/dev/null || true | ||
| echo "${{ secrets.DEPLOY_HOST_KEY }}" >> ~/.ssh/known_hosts | ||
|
|
||
| - name: SSH and Deploy | ||
| env: | ||
| HARBOR_PASS: ${{ secrets.HARBOR_PASS }} | ||
| HARBOR_REG: ${{ secrets.HARBOR_REG }} | ||
| HARBOR_USERNAME: ${{ secrets.HARBOR_USERNAME }} | ||
| run: | | ||
| ssh deploy-user@${{ secrets.CONTAINER_IP }} -T \ | ||
| -o SendEnv=HARBOR_PASS \ | ||
| -o SendEnv=HARBOR_REG \ | ||
| -o SendEnv=HARBOR_USERNAME \ | ||
| bash -s << 'EOF' | ||
| set -e | ||
| cd /home/deploy-user/SeeFT | ||
| git fetch origin feat/mitomen/261/CI-CD-Pipeline | ||
| git reset --hard origin/feat/mitomen/261/CI-CD-Pipeline | ||
| git checkout -B feat/mitomen/261/CI-CD-Pipeline origin/feat/mitomen/261/CI-CD-Pipeline | ||
| echo "$HARBOR_PASS" | docker login "$HARBOR_REG" -u "$HARBOR_USERNAME" --password-stdin | ||
| docker compose -f docker-compose.cd.yml pull | ||
| docker compose -f docker-compose.cd.yml up -d | ||
| docker image prune -f | ||
| EOF | ||
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,85 @@ | ||||||||
| name: CI | ||||||||
|
|
||||||||
| on: | ||||||||
| push: | ||||||||
| branches: | ||||||||
| - main | ||||||||
| - feat/mitomen/261/CI-CD-Pipeline | ||||||||
| workflow_call: | ||||||||
| workflow_dispatch: | ||||||||
|
|
||||||||
| jobs: | ||||||||
| build-and-push: | ||||||||
| runs-on: ubuntu-latest | ||||||||
| steps: | ||||||||
| - name: Check out the repo | ||||||||
| uses: actions/checkout@v6 | ||||||||
| with: | ||||||||
| submodules: recursive | ||||||||
| token: ${{ secrets.GH_PAT || github.token }} | ||||||||
|
|
||||||||
| - name: Connect to Tailscale | ||||||||
| uses: tailscale/github-action@v2 | ||||||||
| with: | ||||||||
| oauth-client-id: ${{ secrets.TAILSCALE_OAUTH_CLIENT_ID }} | ||||||||
| oauth-secret: ${{ secrets.TAILSCALE_OAUTH_CLIENT_SECRET }} | ||||||||
| tags: tag:ci | ||||||||
|
|
||||||||
| - name: Configure Insecure Registry | ||||||||
| run: | | ||||||||
| sudo service docker stop | ||||||||
| echo "{\"insecure-registries\": [\"${{ secrets.HARBOR_REG }}\"]}" | sudo tee /etc/docker/daemon.json | ||||||||
| sudo service docker start | ||||||||
|
|
||||||||
| - name: Set up Docker Buildx | ||||||||
| uses: docker/setup-buildx-action@v3 | ||||||||
| with: | ||||||||
| driver-opts: network=host | ||||||||
| buildkitd-config-inline: | | ||||||||
| [registry."${{ secrets.HARBOR_REG }}"] | ||||||||
| http = true | ||||||||
| insecure = true | ||||||||
|
FastDefence marked this conversation as resolved.
|
||||||||
|
|
||||||||
| - name: Log in to Harbor | ||||||||
| uses: docker/login-action@v3 | ||||||||
| with: | ||||||||
| registry: ${{ secrets.HARBOR_REG }} | ||||||||
| username: ${{ secrets.HARBOR_USERNAME }} | ||||||||
| password: ${{ secrets.HARBOR_PASS }} | ||||||||
|
|
||||||||
| - name: Create .env file | ||||||||
| run: | | ||||||||
| mkdir -p mobile/env | ||||||||
| printf '%s' "${{ secrets.SEEFT_MOBILE_ENVS }}" > mobile/env/.env | ||||||||
|
|
||||||||
| - name: Build and Push API | ||||||||
| uses: docker/build-push-action@v5 | ||||||||
| with: | ||||||||
| context: ./api | ||||||||
| file: ./api/prod.Dockerfile | ||||||||
| push: true | ||||||||
| tags: ${{ secrets.HARBOR_REG }}/seeft/api:latest | ||||||||
| cache-from: type=gha | ||||||||
|
|
||||||||
| - name: Build and Push Admin | ||||||||
| uses: docker/build-push-action@v5 | ||||||||
| with: | ||||||||
| context: ./admin | ||||||||
| file: ./admin/prod.Dockerfile | ||||||||
| push: true | ||||||||
| tags: ${{ secrets.HARBOR_REG }}/seeft/admin:latest | ||||||||
| cache-from: type=gha | ||||||||
|
|
||||||||
| - name: Build and Push Mobile | ||||||||
| uses: docker/build-push-action@v5 | ||||||||
| with: | ||||||||
| context: ./mobile | ||||||||
| file: ./mobile/Dockerfile | ||||||||
| push: true | ||||||||
| tags: ${{ secrets.HARBOR_REG }}/seeft/mobile:latest | ||||||||
| cache-from: type=gha | ||||||||
|
Comment on lines
+55
to
+80
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Avoid Lines 60, 69, and 78 publish only Suggested fix+ - name: Set image tag
+ run: echo "IMAGE_TAG=${GITHUB_SHA}" >> $GITHUB_ENV
+
- name: Build and Push API
uses: docker/build-push-action@v5
with:
context: ./api
file: ./api/prod.Dockerfile
push: true
- tags: ${{ secrets.HARBOR_REG }}/seeft/api:latest
+ tags: |
+ ${{ secrets.HARBOR_REG }}/seeft/api:${{ env.IMAGE_TAG }}
+ ${{ secrets.HARBOR_REG }}/seeft/api:latest
cache-from: type=gha🤖 Prompt for AI AgentsThere was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Harbor GC の動作についてHarbor でイメージを削除しても、ストレージはすぐに解放されません。GC を実行することで、マニフェストから参照されなくなったブロブ(blob)がファイルシステムから削除されます。
解決策SHA タグ付きイメージを自動的に削除するには、Tag Retention Rules(タグ保持ポリシー) を Harbor の UI で設定する必要があります。 リポジトリには多数のイメージタグが急速に蓄積されることがあり、それらは大量のストレージを消費します。 Harbor システム管理者は、リポジトリに対して特定のタグをどれだけ保持するかのルールを定義できます。ルールはプロジェクト単位ではなくリポジトリ単位で定義します。 設定例:「最新 N 件のタグのみ保持」というルールを各リポジトリに設定することで、古い SHA タグのイメージを自動削除できます。
まとめ
SHA タグを導入するのであれば、Harbor の 「Tag Retention」 機能で「最新 N 件のみ保持」ポリシーを設定することを推奨します。 🧠 Learnings used |
||||||||
|
|
||||||||
| trigger-cd: | ||||||||
| needs: build-and-push | ||||||||
| uses: ./.github/workflows/deployment-prod.yml | ||||||||
| secrets: inherit | ||||||||
| Original file line number | Diff line number | Diff line change | |||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,43 @@ | |||||||||||||||||
| version: "3" | |||||||||||||||||
| services: | |||||||||||||||||
| cloudflare: | |||||||||||||||||
| image: "cloudflare/cloudflared:latest" | |||||||||||||||||
| container_name: "nutfes-seeft-web" | |||||||||||||||||
| volumes: ["./web/prod:/home/nonroot/.cloudflared"] | |||||||||||||||||
| command: tunnel run | |||||||||||||||||
|
|
|||||||||||||||||
| mobile: | |||||||||||||||||
| image: ${HARBOR_REG}/seeft/mobile:latest | |||||||||||||||||
| container_name: "nutfes-seeft-mobile" | |||||||||||||||||
| command: "python3 ./python/server.py" | |||||||||||||||||
| ports: ["45029:45029"] | |||||||||||||||||
| environment: | |||||||||||||||||
| NEXT_PUBLIC_APP_ENV: "production" | |||||||||||||||||
| depends_on: ["api"] | |||||||||||||||||
| restart: always | |||||||||||||||||
|
|
|||||||||||||||||
| api: | |||||||||||||||||
| image: ${HARBOR_REG}/seeft/api:latest | |||||||||||||||||
| container_name: "nutfes-seeft-api" | |||||||||||||||||
| volumes: ["./api:/env/app"] | |||||||||||||||||
| command: sh -c "go build -o main main.go && ./main" | |||||||||||||||||
|
Comment on lines
+22
to
+23
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don’t compile Go at container startup in CD compose. Lines 22-23 bind-mount source and run Suggested direction api:
image: ${HARBOR_REG}/seeft/api:latest
container_name: "nutfes-seeft-api"
- volumes: ["./api:/env/app"]
- command: sh -c "go build -o main main.go && ./main"
+ # rely on the image artifact built in CI
+ # command should be provided by Dockerfile CMD/ENTRYPOINT
env_file: ["./api/env/seeft.env"]
ports: ["1234:1234"]
restart: always🤖 Prompt for AI AgentsThere was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
なぜ Dockerfile 内でビルドすべきか
|
|||||||||||||||||
| env_file: ["./api/env/seeft.env"] | |||||||||||||||||
|
coderabbitai[bot] marked this conversation as resolved.
|
|||||||||||||||||
| ports: ["1234:1234"] | |||||||||||||||||
| restart: always | |||||||||||||||||
|
|
|||||||||||||||||
| admin: | |||||||||||||||||
| image: ${HARBOR_REG}/seeft/admin:latest | |||||||||||||||||
| container_name: "nutfes-seeft-admin" | |||||||||||||||||
| command: sh -c "npm install && npm run build && npm run start" | |||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Avoid runtime Line 31 makes startup dependent on live package install/build, increasing failure risk and startup time. Prefer running only the prebuilt app command from the image. 🤖 Prompt for AI AgentsThere was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: Length of output: 147 🏁 Script executed: Length of output: 283
現在の 以下のように # admin/prod.Dockerfile
FROM node:16.13.0
WORKDIR /app/next-project/seeft-admin
COPY ./ /app
ENV NEXT_PUBLIC_APP_ENV production
# ← ここでビルドまで完結させる
RUN npm ci && npm run build
CMD ["npm", "run", "start"]そして admin:
image: ${HARBOR_REG}/seeft/admin:latest
container_name: "nutfes-seeft-admin"
# command は不要(DockerfileのCMDが使われる)
ports: ["5000:3000"]
environment:
NEXT_PUBLIC_APP_ENV: "production"
stdin_open: true
tty: true
depends_on: ["api"]
restart: alwaysこの変更のメリット:
なお、 🧠 Learnings used |
|||||||||||||||||
| ports: | |||||||||||||||||
| - "5000:3000" | |||||||||||||||||
| environment: | |||||||||||||||||
| NEXT_PUBLIC_APP_ENV: "production" | |||||||||||||||||
| stdin_open: true | |||||||||||||||||
| tty: true | |||||||||||||||||
| depends_on: [api] | |||||||||||||||||
| restart: always | |||||||||||||||||
|
|
|||||||||||||||||
| networks: | |||||||||||||||||
| default: | |||||||||||||||||
| name: seeft-default | |||||||||||||||||
Uh oh!
There was an error while loading. Please reload this page.