Aggiorna la configurazione di deploy su GKE e rimuovi il file docker-compose.yml
Some checks failed
GKE Deploy / build-and-deploy (push) Failing after 1m57s
Some checks failed
GKE Deploy / build-and-deploy (push) Failing after 1m57s
This commit is contained in:
@@ -1,22 +1,50 @@
|
|||||||
name: Deploy
|
name: GKE Deploy
|
||||||
on: [push]
|
on: [push]
|
||||||
|
|
||||||
|
env:
|
||||||
|
PROJECT_ID: deployments-485614
|
||||||
|
REGION: europe-west1
|
||||||
|
REPO_NAME: gitea-repo # Assicurati di aver creato questo repo su Artifact Registry!
|
||||||
|
IMAGE_NAME: demo-app
|
||||||
|
CLUSTER_NAME: gitea-cluster
|
||||||
|
CLUSTER_ZONE: europe-west1-b
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
deploy:
|
build-and-deploy:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
container:
|
|
||||||
image: ghcr.io/catthehacker/ubuntu:act-20.04
|
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout del codice
|
- name: Checkout
|
||||||
uses: actions/checkout@v3
|
uses: actions/checkout@v3
|
||||||
|
|
||||||
- name: Deploy
|
# 1. Login su Google Cloud
|
||||||
run: |
|
- name: Google Auth
|
||||||
echo "Deploying with DOMAIN=${{ vars.DOMAIN }}"
|
uses: google-github-actions/auth@v1
|
||||||
DOMAIN="${{ vars.DOMAIN }}" docker compose down --remove-orphans
|
with:
|
||||||
DOMAIN="${{ vars.DOMAIN }}" docker compose up -d --build
|
credentials_json: ${{ secrets.GCP_SA_KEY }}
|
||||||
|
|
||||||
- name: Pulizia
|
# 2. Setup Strumenti Google
|
||||||
run: docker system prune -f
|
- name: Set up Cloud SDK
|
||||||
|
uses: google-github-actions/setup-gcloud@v1
|
||||||
|
|
||||||
|
# 3. Configura Docker per Google
|
||||||
|
- name: Docker Auth
|
||||||
|
run: gcloud auth configure-docker ${{ env.REGION }}-docker.pkg.dev
|
||||||
|
|
||||||
|
# 4. Build e Push dell'immagine
|
||||||
|
- name: Build and Push
|
||||||
|
run: |
|
||||||
|
# Costruiamo il tag completo dell'immagine
|
||||||
|
IMAGE_TAG=${{ env.REGION }}-docker.pkg.dev/${{ env.PROJECT_ID }}/${{ env.REPO_NAME }}/${{ env.IMAGE_NAME }}:${{ gitea.sha }}
|
||||||
|
|
||||||
|
# Costruiamo e carichiamo
|
||||||
|
docker build -t $IMAGE_TAG .
|
||||||
|
docker push $IMAGE_TAG
|
||||||
|
|
||||||
|
# 5. Aggiorna Kubernetes
|
||||||
|
- name: Deploy to GKE
|
||||||
|
run: |
|
||||||
|
gcloud components install gke-gcloud-auth-plugin
|
||||||
|
gcloud container clusters get-credentials ${{ env.CLUSTER_NAME }} --zone ${{ env.CLUSTER_ZONE }}
|
||||||
|
|
||||||
|
# Aggiorna l'immagine nel deployment esistente
|
||||||
|
kubectl set image deployment/demo-app demo-container=${{ env.REGION }}-docker.pkg.dev/${{ env.PROJECT_ID }}/${{ env.REPO_NAME }}/${{ env.IMAGE_NAME }}:${{ gitea.sha }}
|
||||||
30
Dockerfile
30
Dockerfile
@@ -1,30 +1,2 @@
|
|||||||
# Build stage
|
|
||||||
FROM node:20-alpine AS build
|
|
||||||
|
|
||||||
WORKDIR /app
|
|
||||||
|
|
||||||
# Copia i file di dipendenze
|
|
||||||
COPY package*.json ./
|
|
||||||
|
|
||||||
# Installa le dipendenze
|
|
||||||
RUN npm ci
|
|
||||||
|
|
||||||
# Copia il resto dei file
|
|
||||||
COPY . .
|
|
||||||
|
|
||||||
# Build dell'applicazione
|
|
||||||
RUN npm run build
|
|
||||||
|
|
||||||
# Production stage
|
|
||||||
FROM nginx:alpine
|
FROM nginx:alpine
|
||||||
|
RUN echo "<h1>Ciao da Gitea Actions su GKE! v1</h1>" > /usr/share/nginx/html/index.html
|
||||||
# Copia i file buildati
|
|
||||||
COPY --from=build /app/dist /usr/share/nginx/html
|
|
||||||
|
|
||||||
# Copia la configurazione nginx personalizzata
|
|
||||||
COPY nginx.conf /etc/nginx/conf.d/default.conf
|
|
||||||
|
|
||||||
# Espone la porta 80
|
|
||||||
EXPOSE 80
|
|
||||||
|
|
||||||
CMD ["nginx", "-g", "daemon off;"]
|
|
||||||
@@ -1,36 +0,0 @@
|
|||||||
version: '3.8'
|
|
||||||
|
|
||||||
services:
|
|
||||||
vue-app:
|
|
||||||
build:
|
|
||||||
context: .
|
|
||||||
dockerfile: Dockerfile
|
|
||||||
container_name: vue-demo-app
|
|
||||||
restart: unless-stopped
|
|
||||||
networks:
|
|
||||||
- web_proxy
|
|
||||||
labels:
|
|
||||||
- "traefik.enable=true"
|
|
||||||
|
|
||||||
# HTTP Router
|
|
||||||
- "traefik.http.routers.vue-demo.rule=Host(`${DOMAIN}`)"
|
|
||||||
- "traefik.http.routers.vue-demo.entrypoints=web"
|
|
||||||
# - "traefik.http.routers.vue-demo.middlewares=redirect-to-https"
|
|
||||||
|
|
||||||
# HTTPS Router
|
|
||||||
- "traefik.http.routers.vue-demo-secure.rule=Host(`${DOMAIN}`)"
|
|
||||||
- "traefik.http.routers.vue-demo-secure.entrypoints=websecure"
|
|
||||||
- "traefik.http.routers.vue-demo-secure.tls=true"
|
|
||||||
- "traefik.http.routers.vue-demo-secure.tls.certresolver=letsencrypt"
|
|
||||||
|
|
||||||
# Service
|
|
||||||
- "traefik.http.services.vue-demo.loadbalancer.server.port=80"
|
|
||||||
|
|
||||||
# Middleware per redirect HTTP -> HTTPS
|
|
||||||
# - "traefik.http.middlewares.redirect-to-https.redirectscheme.scheme=https"
|
|
||||||
# - "traefik.http.middlewares.redirect-to-https.redirectscheme.permanent=true"
|
|
||||||
|
|
||||||
networks:
|
|
||||||
web_proxy:
|
|
||||||
external: true
|
|
||||||
|
|
||||||
31
k8s/deployment.yml
Normal file
31
k8s/deployment.yml
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
apiVersion: apps/v1
|
||||||
|
kind: Deployment
|
||||||
|
metadata:
|
||||||
|
name: demo-app
|
||||||
|
spec:
|
||||||
|
replicas: 1
|
||||||
|
selector:
|
||||||
|
matchLabels:
|
||||||
|
app: demo-app
|
||||||
|
template:
|
||||||
|
metadata:
|
||||||
|
labels:
|
||||||
|
app: demo-app
|
||||||
|
spec:
|
||||||
|
containers:
|
||||||
|
- name: demo-container
|
||||||
|
image: nginx:alpine # Verrà sostituita dalla pipeline
|
||||||
|
ports:
|
||||||
|
- containerPort: 80
|
||||||
|
---
|
||||||
|
apiVersion: v1
|
||||||
|
kind: Service
|
||||||
|
metadata:
|
||||||
|
name: demo-service
|
||||||
|
spec:
|
||||||
|
type: LoadBalancer
|
||||||
|
selector:
|
||||||
|
app: demo-app
|
||||||
|
ports:
|
||||||
|
- port: 80
|
||||||
|
targetPort: 80
|
||||||
Reference in New Issue
Block a user