-
Notifications
You must be signed in to change notification settings - Fork 0
71 lines (60 loc) · 2.28 KB
/
deploy.yml
File metadata and controls
71 lines (60 loc) · 2.28 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
name: Deploy Potpie Service to Lightsail Kubernetes
on:
push:
branches: [ main, master ]
workflow_dispatch:
env:
DOCKER_EMAIL: digital@pixdata.io
DOCKER_USERNAME: pagewings
IMAGE_NAME: coderide-potpie-service
REGISTRY: docker.io
jobs:
build-and-deploy:
environment: master
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master'
name: Build, Push and Deploy Docker Image
steps:
# 1️⃣ Checkout codice
- name: Checkout code
uses: actions/checkout@v4
# 2️⃣ Setup Docker Buildx
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
# 3️⃣ Login a Docker Hub
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ env.DOCKER_EMAIL }}
password: ${{ secrets.DOCKER_PASSWORD }}
# 4️⃣ Crea variabile con lo short SHA (tag univoco)
- name: Extract short commit SHA
id: vars
run: echo "SHA=$(echo $GITHUB_SHA | cut -c1-7)" >> $GITHUB_ENV
# 5️⃣ Build e push dell'immagine su Docker Hub
- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
context: .
push: true
tags: |
${{ env.REGISTRY }}/${{ env.DOCKER_USERNAME }}/${{ env.IMAGE_NAME }}:latest
${{ env.REGISTRY }}/${{ env.DOCKER_USERNAME }}/${{ env.IMAGE_NAME }}:${{ env.SHA }}
cache-from: type=gha
cache-to: type=gha,mode=max
# 6️⃣ Setup kubectl per accedere al cluster K3s
- name: Setup kubectl
uses: azure/setup-kubectl@v3
with:
version: 'latest'
- name: Configure kubectl
run: |
mkdir -p ~/.kube
echo "${{ secrets.KUBE_CONFIG }}" | base64 -d > ~/.kube/config
chmod 600 ~/.kube/config
# 7️⃣ Aggiorna l'immagine nel Deployment di Kubernetes
- name: Update image in Kubernetes
run: |
kubectl set image deployment/potpie-service potpie-service=${{ env.REGISTRY }}/${{ env.DOCKER_USERNAME }}/${{ env.IMAGE_NAME }}:${{ env.SHA }} --namespace=default
kubectl rollout status deployment/potpie-service --namespace=default
kubectl get pods -l app=potpie-service --namespace=default