Skip to content
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

ArgoCD対応 #315

Merged
merged 21 commits into from
Dec 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
name: CD for v3(main)
name: CD for main

on:
push:
branches:
- v3
- main
workflow_dispatch:

env:
Expand All @@ -16,6 +16,8 @@ jobs:
outputs:
tag_exists: ${{ steps.check_docker_hub.outputs.tag_exists }}
JETDISC_VERSION: ${{ steps.check_docker_hub.outputs.JETDISC_VERSION }}
PREVIOIUS_LATEST_TAG: ${{ steps.get_previous_latest_tag.outputs.PREVIOIUS_LATEST_TAG }}
LATEST_TAG: ${{ steps.genelate_latest_tag.outputs.LATEST_TAG }}
steps:
- name: Check out the repo
uses: actions/[email protected]
Expand All @@ -27,13 +29,21 @@ jobs:
id: check_docker_hub
run: |
DOCKER_HUB_TAGS=$(curl -s ${{ env.DOCKER_TAG_API_URI }} | jq -r '.results[] | .name')
if [ $(echo $DOCKER_HUB_TAGS | grep -c $JETDISC_VERSION) -eq 1 ]; then
if echo "$DOCKER_HUB_TAGS" | grep -q "^$JETDISC_VERSION$"; then
echo "Tag $JETDISC_VERSION already exists on Docker Hub."
else
echo "Tag $JETDISC_VERSION does not exist on Docker Hub."
echo "tag_exists=false" >> $GITHUB_OUTPUT
echo "JETDISC_VERSION=$JETDISC_VERSION" >> $GITHUB_OUTPUT
fi
- name: Get Current Latest Tag
id: get_previous_latest_tag
run: |
echo "PREVIOIUS_LATEST_TAG=$(curl -s $DOCKER_TAG_API_URI | jq -r '.results | sort_by(.last_updated) | last | .name')" >> $GITHUB_OUTPUT
- name: Genelate Latest Tag by commit hash
id: genelate_latest_tag
run: |
echo "LATEST_TAG=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT

Build-and-Push-to-Docker-Hub:
needs:
Expand All @@ -43,5 +53,6 @@ jobs:
JETDISC_VERSION: ${{ needs.Prepare.outputs.JETDISC_VERSION }}
IMAGE_REPOSITORY: na2na
IMAGE_NAME: jetdisc
LATEST_TAG: ${{ needs.Prepare.outputs.LATEST_TAG }}
uses: ./.github/workflows/image-build-and-publish.yml
secrets: inherit
18 changes: 17 additions & 1 deletion .github/workflows/cd-for-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ on:
pull_request:
branches:
- main
- v3
types:
- opened
- reopened
Expand All @@ -24,6 +23,23 @@ jobs:
- ubuntu-latest
steps:
- uses: actions/[email protected]
- name: Checkout repository
uses: actions/[email protected]
- name: Setup asdf
uses: asdf-vm/actions/[email protected]
continue-on-error: true
- name: install ffmpeg dependencies
run: |
sudo apt-get update
sudo apt-get install -y nasm
- name: Cache asdf
uses: actions/cache@v3
with:
path: |
~/.asdf
key: ${{ runner.os }}-asdf-${{ hashFiles('**/.tool-versions') }}
- name: asdf install
uses: asdf-vm/actions/[email protected]
ci:
uses: ./.github/workflows/ci.yml
secrets: inherit
Expand Down
1 change: 0 additions & 1 deletion .github/workflows/enable-auto-merge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ on:
- ready_for_review
branches:
- main
- v3

jobs:
enable-auto-merge:
Expand Down
9 changes: 6 additions & 3 deletions .github/workflows/image-build-and-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ on:
IMAGE_NAME:
required: true
type: string
LATEST_TAG:
required: true
type: string
secrets: {}

jobs:
Expand Down Expand Up @@ -47,7 +50,7 @@ jobs:
docker buildx bake \
-f 'infra/docker/image-bake.hcl' \
--builder="${{ steps.buildx.outputs.name }}" \
--set='web.tags=${{ inputs.IMAGE_REPOSITORY }}/${{ inputs.IMAGE_NAME }}:${{ inputs.JETDISC_VERSION }}' \
--set='web.tags=${{ inputs.IMAGE_REPOSITORY }}/${{ inputs.IMAGE_NAME }}:${{ steps.prepare-for-build.outputs.sha_short }}' \
--set='web.tags=${{ inputs.IMAGE_REPOSITORY }}/${{ inputs.IMAGE_NAME }}:release' \
--set='app.tags=${{ inputs.IMAGE_REPOSITORY }}/${{ inputs.IMAGE_NAME }}:${{ inputs.JETDISC_VERSION }}' \
--set='app.tags=${{ inputs.IMAGE_REPOSITORY }}/${{ inputs.IMAGE_NAME }}:${{ inputs.LATEST_TAG }}' \
--set='app.tags=${{ inputs.IMAGE_REPOSITORY }}/${{ inputs.IMAGE_NAME }}:release' \
--push
5 changes: 3 additions & 2 deletions .tool-versions
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
nodejs 20.9.0
pnpm 8.10.5
nodejs 20.10.0
pnpm 8.11.0
python 3.11.6
ffmpeg 6.1
kubectl 1.28.4
argocd 2.9.2
1 change: 1 addition & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"source.fixAll.eslint": "always"
},
"cSpell.words": [
"argocd",
"jetdisc",
"libsodium",
"swcrc",
Expand Down
33 changes: 27 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,35 @@ Pythonは、`@discordjs/opus`の入れるのに必要です。

## Helmを利用してデプロイする

### リソースの作成
### ArgoCDを使わない場合

1. `infra/k8s/manifests/secret.example.yml`を参考に、同ディレクトリに`secret.yml`を作成する
#### リソースの作成

1. `kubectl create namespace jetdisc`でNamespaceを作成する
2. `infra/k8s/manifests/secret.example.yml`を参考に、同ディレクトリに`secret.yml`を作成する
1. SecretはBase64エンコードすること
2. `kubectl apply -f infra/k8s/manifests/secret.yml`でSecretの適用をする
3. `helm install {任意の名前/バージョン名など} ./infra/k8s/helm`
3. `kubectl apply -f infra/k8s/manifests/secret.yml -n jetdisc`でSecretの適用をする
4. `helm install -n jetdisc {任意の名前/バージョン名など} ./infra/k8s/helm`

### リソースの削除
#### リソースの削除

1. `helm uninstall {任意の名前/バージョン名など}`
2. `kubectl delete -f infra/k8s/manifests/secret.yml`
2. `kubectl delete -f infra/k8s/manifests/secret.yml`でSecretの削除をする
3. `kubectl delete namespace jetdisc`でNamespaceの削除をする

### ArgoCDを使う場合

#### リソースの作成

1. ArgoCDと同じクラスターにログインする
2. `kubectl create namespace jetdisc`でNamespaceを作成する
3. `infra/k8s/manifests/secret.example.yml`を参考に、同ディレクトリに`secret.yml`を作成する
1. SecretはBase64エンコードすること
4. `kubectl apply -f infra/k8s/manifests/secret.yml -n jetdisc`でSecretの適用をする
5. `kubectl apply -f infra/k8s/argocd/jetdisc.yaml`でArgoCDの適用をする

#### リソースの削除

1. `kubectl delete -f infra/k8s/argocd/jetdisc.yaml`
2. `kubectl delete -f infra/k8s/manifests/secret.yml`でSecretの削除をする
3. `kubectl delete namespace jetdisc`でNamespaceの削除をする
39 changes: 3 additions & 36 deletions infra/docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,47 +1,14 @@
ARG NODE_VERSION=20.9.0-bookworm
ARG DEBIAN_VERSION=bookworm-20231120-slim
ARG NODE_VERSION=20.10.0-bookworm

FROM debian:${DEBIAN_VERSION} AS base

ARG PYTHON_VERSION=3.11.6
FROM node:${NODE_VERSION} AS builder

RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
--mount=type=cache,target=/var/lib/apt,sharing=locked \
rm -f /etc/apt/apt.conf.d/docker-clean \
; echo 'Binary::apt::APT::Keep-Downloaded-Packages "true";' > /etc/apt/apt.conf.d/keep-cache \
&& apt-get update \
&& apt-get install -yqq --no-install-recommends \
build-essential \
ca-certificates \
libssl-dev \
zlib1g-dev \
libncurses5-dev \
libncursesw5-dev \
libreadline-dev \
libsqlite3-dev \
libgdbm-dev \
libdb5.3-dev \
libbz2-dev \
libexpat1-dev \
liblzma-dev \
tk-dev \
libffi-dev \
wget

RUN wget https://www.python.org/ftp/python/${PYTHON_VERSION}/Python-${PYTHON_VERSION}.tgz \
&& tar -xzf Python-${PYTHON_VERSION}.tgz \
&& cd Python-${PYTHON_VERSION} \
&& ./configure --enable-optimizations \
&& make -j 8 \
&& make altinstall \
&& cd .. \
&& rm -rf Python-${PYTHON_VERSION}.tgz Python-${PYTHON_VERSION} \
&& apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false \
&& rm -rf /var/lib/apt/lists/*

FROM node:${NODE_VERSION} as builder

COPY --from=base /usr/local /usr/local
python3

RUN corepack enable

Expand Down
2 changes: 1 addition & 1 deletion infra/docker/image-bake.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ group "default" {
}

target "app" {
dockerfile = "Dockerfile"
dockerfile = "infra/docker/Dockerfile"
platforms = ["linux/amd64", "linux/arm64"]
cache-to = ["type=local,dest=/tmp/.buildx-cache"]
cache-from = ["type=local,src=/tmp/.buildx-cache"]
Expand Down
13 changes: 13 additions & 0 deletions infra/k8s/argocd/figure.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
```mermaid
graph TD
A[1. topic PRが提出される] -->|CIやレビューを通過する| B[3. デフォルトブランチにマージされる]
B --> C[4. デフォルトブランチのpackage.jsonのversionと同じタグのイメージを確認]
C -->|存在している| D[4.5. 何もしない]
C -->|存在していない| E[5. イメージのビルドとpush]
E --> F[6. Renovateがvalues.yamlとイメージレジストリ上の最新イメージタグを比較]
F -->|新しいバージョンがある場合| G[7. 自動でPRを提出]
F -->|新しいバージョンがない場合| H[8. 何もしない]
G --> I[8. PRがマージされる]
I --> J[9. ArgoCDがチャートの差分を検知しデプロイ]

```
32 changes: 32 additions & 0 deletions infra/k8s/argocd/jetdisc.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
apiVersion: argoproj.io/v1alpha1
kind: ApplicationSet
metadata:
name: jetdisc-applicationset
namespace: argocd
spec:
generators:
- list:
elements:
- name: jetdisc
repo: https://github.com/na2na-p/jetdisc.git
path: infra/k8s/helm
destServer: https://kubernetes.default.svc
destNamespace: jetdisc
# TODO: v3のマージ進んできたらブランチ名ごとmainに変更する
targetRevision: v3
template:
metadata:
name: "{{name}}"
spec:
project: default
source:
repoURL: "{{repo}}"
targetRevision: "{{targetRevision}}"
path: "{{path}}"
destination:
server: "{{destServer}}"
namespace: "{{destNamespace}}"
syncPolicy:
automated:
selfHeal: true
prune: true
2 changes: 1 addition & 1 deletion infra/k8s/helm/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ type: application
# This is the chart version. This version number should be incremented each time you make changes
# to the chart and its templates, including the app version.
# Versions are expected to follow Semantic Versioning (https://semver.org/)
version: 3.0.0-helm-beta1
version: 3.0.0-helm

# This is the version number of the application being deployed. This version number should be
# incremented each time you make changes to the application. Versions are not expected to
Expand Down
6 changes: 3 additions & 3 deletions infra/k8s/helm/templates/NOTES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,17 @@
6. デプロイメントの状況を確認するには、以下のコマンドを実行してください:

```
kubectl get deployment {{ include "jetdisc.fullname" . }}
kubectl get deployment {{ include "jetdisc.fullname" . }} -n {{ .Release.Namespace }}
```

7. リリースの削除には、以下のコマンドを実行してください:

```
helm delete {{ include "jetdisc.fullname" . }}
helm delete {{ include "jetdisc.fullname" . }} -n {{ .Release.Namespace }}
```

8. アプリケーションのログを確認するには、以下のコマンドを実行してください:

```
kubectl logs -f deployment/{{ include "jetdisc.fullname" . }}
kubectl logs -f deployment/{{ include "jetdisc.fullname" . }} -n {{ .Release.Namespace }}
```
3 changes: 2 additions & 1 deletion infra/k8s/helm/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ replicaCount: 1

image:
repository: na2na/jetdisc
tag: "preview"
tag: "3.0.1"
registry: docker.io
pullPolicy: IfNotPresent

secret:
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "jetdisc",
"version": "3.0.0-beta1",
"version": "3.0.1",
"description": "",
"type": "module",
"main": "built/index.js",
Expand Down
13 changes: 12 additions & 1 deletion renovate.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,17 @@
{
"matchUpdateTypes": ["major"],
"addLabels": ["major update"]
},
{
"datasources": ["docker"],
"packageNames": ["na2na/jetdisc"],
"matchManagers": ["helm-values"]
},
{
"groupName": "JetDisc updates",
"addLabels": ["Infra"],
"matchPackageNames": ["docker.io/na2na/jetdisc"]
}
]
],
"ignoreDeps": ["python"]
}
Loading