Ir al contenido

Astro Application Deployment + CI/CD

Workflow for compiling Astro in Docker clusters

0views

In this document, we document the pipeline necessary to take the static website (SSG) or with SSR (Server Side Rendering) from the local development environment to production.

It is required to create a .github/workflows/deploy.yml file that compiles the files, validates Type checking, and uploads the compiled artifact /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/

For projects hosted internally on your NAS or private infrastructure (HomeLab or Local VPS), we will package Astro in an optimized image based on 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;"]