diff --git a/.gitea/workflows/deploy.yml b/.gitea/workflows/deploy.yml index 5592565..c7469e2 100644 --- a/.gitea/workflows/deploy.yml +++ b/.gitea/workflows/deploy.yml @@ -1,22 +1,50 @@ -name: Deploy +name: GKE Deploy 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: - deploy: + build-and-deploy: runs-on: ubuntu-latest - - container: - image: ghcr.io/catthehacker/ubuntu:act-20.04 - steps: - - name: Checkout del codice + - name: Checkout uses: actions/checkout@v3 - - name: Deploy - run: | - echo "Deploying with DOMAIN=${{ vars.DOMAIN }}" - DOMAIN="${{ vars.DOMAIN }}" docker compose down --remove-orphans - DOMAIN="${{ vars.DOMAIN }}" docker compose up -d --build + # 1. Login su Google Cloud + - name: Google Auth + uses: google-github-actions/auth@v1 + with: + credentials_json: ${{ secrets.GCP_SA_KEY }} - - name: Pulizia - run: docker system prune -f \ No newline at end of file + # 2. Setup Strumenti Google + - 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 }} \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 629c3ef..36464a9 100644 --- a/Dockerfile +++ b/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 - -# 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;"] +RUN echo "