Skip to content

Commit 3886bf1

Browse files
committed
feat: testing automatic pod deployment
1 parent db0fd1e commit 3886bf1

1 file changed

Lines changed: 53 additions & 38 deletions

File tree

.github/workflows/deploy.yml

Lines changed: 53 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -6,49 +6,64 @@ on:
66
workflow_dispatch:
77

88
env:
9-
DOCKER_EMAIL: digital@pixdata.io
109
DOCKER_USERNAME: pagewings
1110
IMAGE_NAME: coderide-potpie-service
1211
REGISTRY: docker.io
1312

1413
jobs:
15-
build-and-push:
16-
environment: master
14+
build-and-deploy:
1715
runs-on: ubuntu-latest
1816
if: github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master'
19-
name: Build and Push Docker Image
20-
17+
name: Build, Push and Deploy Docker Image
18+
2119
steps:
22-
- name: Checkout code
23-
uses: actions/checkout@v4
24-
25-
- name: Set up Docker Buildx
26-
uses: docker/setup-buildx-action@v3
27-
28-
- name: Login to Docker Hub
29-
uses: docker/login-action@v3
30-
with:
31-
username: ${{ env.DOCKER_EMAIL }}
32-
password: ${{ secrets.DOCKER_PASSWORD }}
33-
34-
- name: Extract metadata
35-
id: meta
36-
uses: docker/metadata-action@v5
37-
with:
38-
images: ${{ env.REGISTRY }}/${{ env.DOCKER_USERNAME }}/${{ env.IMAGE_NAME }}
39-
tags: |
40-
type=ref,event=branch
41-
type=ref,event=pr
42-
type=sha,prefix={{branch}}-
43-
type=raw,value=latest,enable={{is_default_branch}}
44-
45-
- name: Build and push Docker image
46-
uses: docker/build-push-action@v5
47-
with:
48-
context: .
49-
platforms: linux/amd64,linux/arm64
50-
push: true
51-
tags: ${{ steps.meta.outputs.tags }}
52-
labels: ${{ steps.meta.outputs.labels }}
53-
cache-from: type=gha
54-
cache-to: type=gha,mode=max
20+
# 1️⃣ Checkout codice
21+
- name: Checkout code
22+
uses: actions/checkout@v4
23+
24+
# 2️⃣ Setup Docker Buildx
25+
- name: Set up Docker Buildx
26+
uses: docker/setup-buildx-action@v3
27+
28+
# 3️⃣ Login a Docker Hub
29+
- name: Login to Docker Hub
30+
uses: docker/login-action@v3
31+
with:
32+
username: ${{ env.DOCKER_USERNAME }}
33+
password: ${{ secrets.DOCKER_PASSWORD }}
34+
35+
# 4️⃣ Crea variabile con lo short SHA (tag univoco)
36+
- name: Extract short commit SHA
37+
id: vars
38+
run: echo "SHA=$(echo $GITHUB_SHA | cut -c1-7)" >> $GITHUB_ENV
39+
40+
# 5️⃣ Build e push dell'immagine su Docker Hub
41+
- name: Build and push Docker image
42+
uses: docker/build-push-action@v5
43+
with:
44+
context: .
45+
push: true
46+
tags: |
47+
${{ env.REGISTRY }}/${{ env.DOCKER_USERNAME }}/${{ env.IMAGE_NAME }}:latest
48+
${{ env.REGISTRY }}/${{ env.DOCKER_USERNAME }}/${{ env.IMAGE_NAME }}:${{ env.SHA }}
49+
cache-from: type=gha
50+
cache-to: type=gha,mode=max
51+
52+
# 6️⃣ Setup kubectl per accedere al cluster K3s
53+
- name: Setup kubectl
54+
uses: azure/setup-kubectl@v3
55+
with:
56+
version: 'latest'
57+
58+
- name: Configure kubectl
59+
run: |
60+
mkdir -p ~/.kube
61+
echo "${{ secrets.KUBE_CONFIG }}" | base64 -d > ~/.kube/config
62+
chmod 600 ~/.kube/config
63+
64+
# 7️⃣ Aggiorna l'immagine nel Deployment di Kubernetes
65+
- name: Update image in Kubernetes
66+
run: |
67+
kubectl set image deployment/potpie-service potpie-service=${{ env.REGISTRY }}/${{ env.DOCKER_USERNAME }}/${{ env.IMAGE_NAME }}:${{ env.SHA }} --namespace=default
68+
kubectl rollout status deployment/potpie-service --namespace=default
69+
kubectl get pods -l app=potpie-service --namespace=default

0 commit comments

Comments
 (0)