Ir al contenido

Applicatie-implementatie in Astro + CI/CD

Workflow voor het compileren van Astro in Docker-clusters

0lecturas

In dit document documenteren we de pipeline die nodig is om de statische website (SSG) of met SSR (Server Side Rendering) van de lokale ontwikkelomgeving naar productie te brengen.

Er is een .github/workflows/deploy.yml bestand nodig dat de bestanden compileert, typechecking valideert en het gecompileerde artefact uploadt /dist.

name: Deploy Astro a Producción
on:
push:
branches:
- main
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: pnpm/action-setup@v2
with:
version: 8
- name: Install Dependencies
run: pnpm install --no-frozen-lockfile
- name: Build
run: pnpm run build
- name: RSYNC to Server
run: |
# Ejemplo de despliegue directo a máquina Linux mediante SSH
rsync -avz --delete ./dist/ ${USER}@${SERVER_IP}:/var/www/html/astro/

Voor projecten die intern worden gehost op je NAS of privé-infrastructuur (HomeLab of lokale VPS), verpakken we Astro in een geoptimaliseerde image gebaseerd op Alpine Linux:

# Etapa 1: Construcción
FROM node:20-alpine AS builder
WORKDIR /app
COPY package*.json ./
RUN npm ci
COPY . .
RUN npm run build
# Etapa 2: Servidor
FROM nginx:alpine
COPY --from=builder /app/dist /usr/share/nginx/html
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]