ci: deploy ai assistant via github actions and ghcr
This commit is contained in:
parent
7d31d1a2bd
commit
1a2781a85f
3 changed files with 92 additions and 42 deletions
90
.github/workflows/build-and-deploy-ghcr.yml
vendored
Normal file
90
.github/workflows/build-and-deploy-ghcr.yml
vendored
Normal file
|
|
@ -0,0 +1,90 @@
|
||||||
|
name: build-and-deploy-ghcr
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- main
|
||||||
|
- high-performance
|
||||||
|
workflow_dispatch:
|
||||||
|
|
||||||
|
permissions:
|
||||||
|
contents: read
|
||||||
|
packages: write
|
||||||
|
|
||||||
|
env:
|
||||||
|
IMAGE_NAME: ghcr.io/${{ github.repository_owner }}/${{ github.event.repository.name }}
|
||||||
|
K8S_NAMESPACE: nxtgauge-ai
|
||||||
|
DEPLOYMENT_NAME: nxtgauge-ai-assistant
|
||||||
|
CONTAINER_NAME: ai-assistant
|
||||||
|
APP_KEY: ai-assistant
|
||||||
|
GITOPS_REPO: Traceworks2023/nxtgauge-gitops
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build-deploy:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Checkout
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
fetch-depth: 0
|
||||||
|
|
||||||
|
- name: Set up Docker Buildx
|
||||||
|
uses: docker/setup-buildx-action@v3
|
||||||
|
|
||||||
|
- name: Login to GHCR
|
||||||
|
uses: docker/login-action@v3
|
||||||
|
with:
|
||||||
|
registry: ghcr.io
|
||||||
|
username: ${{ secrets.GHCR_USERNAME }}
|
||||||
|
password: ${{ secrets.DEPLOY_GITHUB_TOKEN }}
|
||||||
|
|
||||||
|
- name: Build and push image
|
||||||
|
id: build
|
||||||
|
uses: docker/build-push-action@v6
|
||||||
|
with:
|
||||||
|
context: .
|
||||||
|
file: Dockerfile
|
||||||
|
push: true
|
||||||
|
platforms: linux/amd64
|
||||||
|
tags: ${{ env.IMAGE_NAME }}:${{ github.sha }}
|
||||||
|
|
||||||
|
- name: Configure kubeconfig
|
||||||
|
run: |
|
||||||
|
set -euo pipefail
|
||||||
|
mkdir -p ~/.kube
|
||||||
|
printf '%s' '${{ secrets.KUBE_CONFIG_DATA }}' | base64 -d > ~/.kube/config
|
||||||
|
chmod 600 ~/.kube/config
|
||||||
|
|
||||||
|
- name: Install kubectl
|
||||||
|
uses: azure/setup-kubectl@v4
|
||||||
|
|
||||||
|
- name: Deploy to Kubernetes
|
||||||
|
env:
|
||||||
|
GHCR_USERNAME: ${{ secrets.GHCR_USERNAME }}
|
||||||
|
GHCR_TOKEN: ${{ secrets.DEPLOY_GITHUB_TOKEN }}
|
||||||
|
run: |
|
||||||
|
set -euo pipefail
|
||||||
|
image_ref="${IMAGE_NAME}@${{ steps.build.outputs.digest }}"
|
||||||
|
kubectl -n "$K8S_NAMESPACE" create secret docker-registry ghcr-regcred --docker-server=ghcr.io --docker-username="$GHCR_USERNAME" --docker-password="$GHCR_TOKEN" --dry-run=client -o yaml | kubectl apply -f -
|
||||||
|
kubectl -n "$K8S_NAMESPACE" patch deployment "$DEPLOYMENT_NAME" --type merge -p '{"spec":{"template":{"spec":{"imagePullSecrets":[{"name":"ghcr-regcred"}]}}}}'
|
||||||
|
kubectl -n "$K8S_NAMESPACE" set image deployment/"$DEPLOYMENT_NAME" "$CONTAINER_NAME"="$image_ref"
|
||||||
|
kubectl -n "$K8S_NAMESPACE" rollout status deployment/"$DEPLOYMENT_NAME" --timeout=10m
|
||||||
|
|
||||||
|
- name: Sync GitOps release
|
||||||
|
env:
|
||||||
|
GITOPS_TOKEN: ${{ secrets.DEPLOY_GITHUB_TOKEN }}
|
||||||
|
run: |
|
||||||
|
set -euo pipefail
|
||||||
|
image_ref="${IMAGE_NAME}@${{ steps.build.outputs.digest }}"
|
||||||
|
git clone "https://${{ secrets.GHCR_USERNAME }}:${GITOPS_TOKEN}@github.com/${GITOPS_REPO}.git" /tmp/nxtgauge-gitops
|
||||||
|
cd /tmp/nxtgauge-gitops
|
||||||
|
./scripts/set-app-release.sh "$APP_KEY" "$image_ref"
|
||||||
|
if git diff --quiet; then
|
||||||
|
echo "GitOps repo already up to date."
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
git config user.name "github-actions[bot]"
|
||||||
|
git config user.email "github-actions[bot]@users.noreply.github.com"
|
||||||
|
git add apps scripts/set-app-release.sh
|
||||||
|
git commit -m "chore(gitops): deploy ${APP_KEY}@${{ github.sha }}"
|
||||||
|
git push origin HEAD:main
|
||||||
40
.github/workflows/sync-to-forgejo.yml
vendored
40
.github/workflows/sync-to-forgejo.yml
vendored
|
|
@ -1,40 +0,0 @@
|
||||||
name: sync-to-forgejo
|
|
||||||
|
|
||||||
on:
|
|
||||||
push:
|
|
||||||
branches:
|
|
||||||
- main
|
|
||||||
- high-performance
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
sync:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
permissions:
|
|
||||||
contents: read
|
|
||||||
steps:
|
|
||||||
- name: Checkout
|
|
||||||
uses: actions/checkout@v4
|
|
||||||
with:
|
|
||||||
fetch-depth: 0
|
|
||||||
|
|
||||||
- name: Push branch to Forgejo
|
|
||||||
env:
|
|
||||||
FORGEJO_SECRET: ${{ secrets.FORGEJO_SECRET || secrets.GITEA_SECRET }}
|
|
||||||
FORGEJO_OWNER: ${{ secrets.FORGEJO_OWNER || 'ashwin' }}
|
|
||||||
FORGEJO_USERNAME: ${{ secrets.FORGEJO_USERNAME || secrets.GITEA_USERNAME || 'ashwin' }}
|
|
||||||
REPO: ${{ github.event.repository.name }}
|
|
||||||
BRANCH: ${{ github.ref_name }}
|
|
||||||
run: |
|
|
||||||
set -euo pipefail
|
|
||||||
test -n "${FORGEJO_SECRET:-}" || { echo "FORGEJO_SECRET is empty"; exit 1; }
|
|
||||||
|
|
||||||
AUTH="$(printf '%s' "${FORGEJO_USERNAME}:${FORGEJO_SECRET}" | base64 -w0)"
|
|
||||||
TARGET="https://ci.nxtgauge.com/${FORGEJO_OWNER}/${REPO}.git"
|
|
||||||
|
|
||||||
git config user.name "github-actions[bot]"
|
|
||||||
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
|
|
||||||
git remote remove forgejo 2>/dev/null || true
|
|
||||||
git remote add forgejo "${TARGET}"
|
|
||||||
|
|
||||||
git -c http.extraHeader="AUTHORIZATION: basic ${AUTH}" push forgejo "HEAD:${BRANCH}" --force
|
|
||||||
git -c http.extraHeader="AUTHORIZATION: basic ${AUTH}" push forgejo --tags --force
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
FROM registry.nxtgauge.com/rust:alpine AS builder
|
FROM rust:alpine AS builder
|
||||||
RUN apk add --no-cache curl ca-certificates bash build-base musl-dev pkgconfig openssl-dev openssl-libs-static
|
RUN apk add --no-cache curl ca-certificates bash build-base musl-dev pkgconfig openssl-dev openssl-libs-static
|
||||||
RUN update-ca-certificates
|
RUN update-ca-certificates
|
||||||
RUN curl -sSf https://sh.rustup.rs | sh -s -- -y --profile minimal --default-toolchain stable
|
RUN curl -sSf https://sh.rustup.rs | sh -s -- -y --profile minimal --default-toolchain stable
|
||||||
|
|
@ -13,7 +13,7 @@ ENV OPENSSL_STATIC=1
|
||||||
ENV OPENSSL_DIR=/usr
|
ENV OPENSSL_DIR=/usr
|
||||||
RUN cargo build --release --target x86_64-unknown-linux-musl
|
RUN cargo build --release --target x86_64-unknown-linux-musl
|
||||||
|
|
||||||
FROM registry.nxtgauge.com/alpine:3.20
|
FROM alpine:3.20
|
||||||
RUN apk add --no-cache ca-certificates
|
RUN apk add --no-cache ca-certificates
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
COPY --from=builder /app/target/x86_64-unknown-linux-musl/release/nxtgauge-ai-assistant /usr/local/bin/nxtgauge-ai-assistant
|
COPY --from=builder /app/target/x86_64-unknown-linux-musl/release/nxtgauge-ai-assistant /usr/local/bin/nxtgauge-ai-assistant
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue