-
Notifications
You must be signed in to change notification settings - Fork 0
80 lines (67 loc) · 2.32 KB
/
build-and-deploy.yml
File metadata and controls
80 lines (67 loc) · 2.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
name: Build and Deploy Atria Docs
on:
push:
branches: [main]
workflow_dispatch: # Manual trigger option
env:
DOCS_IMAGE: sbtl/atria-docs
jobs:
build-and-push:
runs-on: ubuntu-latest
outputs:
image-tag: ${{ steps.generate-tag.outputs.tag }}
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
ref: main
- name: Generate unique image tag
id: generate-tag
run: |
TAG="prod-${GITHUB_SHA::8}-$(date +%s)"
echo "tag=${TAG}" >> $GITHUB_OUTPUT
echo "Generated tag: ${TAG}"
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Build and push docs image
uses: docker/build-push-action@v5
with:
context: .
file: ./Dockerfile
push: true
tags: |
${{ env.DOCS_IMAGE }}:${{ steps.generate-tag.outputs.tag }}
${{ env.DOCS_IMAGE }}:latest
cache-from: type=gha
cache-to: type=gha,mode=max
deploy:
needs: build-and-push
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/main' || github.event_name == 'workflow_dispatch'
steps:
- name: Deploy to k3s
uses: appleboy/ssh-action@v1.0.0
with:
host: ${{ secrets.K3S_HOST }}
username: ${{ secrets.K3S_USER }}
key: ${{ secrets.K3S_SSH_KEY }}
port: ${{ secrets.K3S_PORT }}
script: |
IMAGE_TAG="${{ needs.build-and-push.outputs.image-tag }}"
# Set KUBECONFIG to use user's config
export KUBECONFIG=$HOME/.kube/config
# Pull the new image with specific tag
echo "🚀 Pulling Docker image with tag: ${IMAGE_TAG}"
sudo k3s crictl pull ${{ env.DOCS_IMAGE }}:${IMAGE_TAG}
# Update deployment in atria-docs namespace
echo "Updating docs deployment..."
kubectl set image deployment/docs-deployment docs=${{ env.DOCS_IMAGE }}:${IMAGE_TAG} -n atria-docs
# Wait for rollout to complete
echo "Waiting for rollout..."
kubectl rollout status deployment/docs-deployment -n atria-docs --timeout=300s
echo "✅ Docs deployment completed successfully!"