146 lines
3.4 KiB
Markdown
146 lines
3.4 KiB
Markdown
# CI/CD Setup Instructions
|
|
|
|
## ✅ What's Done
|
|
|
|
1. **Gitea Actions workflow** created (`.gitea/workflows/ci-cd.yaml`)
|
|
- Build job: Verify Astro build works
|
|
- Deploy job: Build Docker image + push to registry + trigger Portainer
|
|
|
|
2. **Docker files** created:
|
|
- `Dockerfile` - Multi-stage build (Node + nginx)
|
|
- `docker-compose.yml` - Local testing
|
|
- `nginx.conf` - SPA routing + cache headers
|
|
- `.dockerignore` - Optimize build
|
|
|
|
3. **Pushed to git** - CI will run on next push to main branch
|
|
|
|
---
|
|
|
|
## 🔧 Manual Steps Required
|
|
|
|
### 1. Configure Gitea Secrets
|
|
|
|
Go to: https://gitlab.impresion3d.pro/root/davidaragon-portfolio/settings/secrets
|
|
|
|
Add these secrets:
|
|
|
|
#### `DOCKER_USERNAME`
|
|
```
|
|
root
|
|
```
|
|
|
|
#### `DOCKER_PASSWORD`
|
|
```
|
|
<your Gitea personal access token with registry permissions>
|
|
```
|
|
|
|
#### `PORTAINER_WEBHOOK_URL`
|
|
```
|
|
<webhook URL from Portainer stack - see step 2>
|
|
```
|
|
|
|
### 2. Create Portainer Stack
|
|
|
|
1. Go to Portainer: http://192.168.1.30:9000
|
|
2. Navigate to: **Stacks** → **Add stack**
|
|
3. Name: `davidaragon-portfolio`
|
|
4. Build method: **Git Repository** or **Web editor**
|
|
|
|
#### Stack compose file:
|
|
|
|
```yaml
|
|
version: '3.8'
|
|
|
|
services:
|
|
portfolio:
|
|
image: gitlab.impresion3d.pro/root/davidaragon-portfolio:latest
|
|
container_name: davidaragon-portfolio
|
|
ports:
|
|
- "8081:80"
|
|
restart: unless-stopped
|
|
environment:
|
|
- NODE_ENV=production
|
|
networks:
|
|
- web
|
|
|
|
networks:
|
|
web:
|
|
external: true
|
|
```
|
|
|
|
5. Deploy the stack
|
|
6. Go to stack **Webhooks** tab
|
|
7. Create webhook for service `portfolio`
|
|
8. Copy webhook URL (format: `http://192.168.1.30:9000/api/stacks/webhooks/...`)
|
|
9. Add this URL as `PORTAINER_WEBHOOK_URL` secret in Gitea (step 1)
|
|
|
|
### 3. Optional: Configure Gitea Runner
|
|
|
|
If no runners registered yet:
|
|
|
|
```bash
|
|
# On server 192.168.1.30 (port 2222)
|
|
docker run -d \
|
|
--name gitea-runner-portfolio \
|
|
--restart unless-stopped \
|
|
-e GITEA_INSTANCE_URL=https://gitlab.impresion3d.pro \
|
|
-e GITEA_RUNNER_REGISTRATION_TOKEN=<your_token> \
|
|
-e GITEA_RUNNER_NAME=ubuntu-latest \
|
|
-v /var/run/docker.sock:/var/run/docker.sock \
|
|
gitea/act_runner:latest
|
|
```
|
|
|
|
Get registration token from: https://gitlab.impresion3d.pro/admin/actions/runners
|
|
|
|
---
|
|
|
|
## 🚀 How It Works
|
|
|
|
### On Every Push to Main:
|
|
|
|
1. **Build job** runs:
|
|
- Install Node.js 20
|
|
- Install dependencies (`npm ci`)
|
|
- Build Astro site (`npm run build`)
|
|
- Upload `dist/` artifact
|
|
|
|
2. **Deploy job** runs (only if build succeeds):
|
|
- Download `dist/` artifact
|
|
- Build Docker image (multi-stage)
|
|
- Push to Gitea registry: `gitlab.impresion3d.pro/root/davidaragon-portfolio:latest`
|
|
- Trigger Portainer webhook → Portainer pulls new image and restarts container
|
|
|
|
### Result:
|
|
- Site auto-deployed to http://192.168.1.30:8081
|
|
- No manual intervention needed after initial setup
|
|
|
|
---
|
|
|
|
## 🧪 Test Locally
|
|
|
|
```bash
|
|
cd ~/code_ubuntu/davidaragon-portfolio
|
|
|
|
# Build and run with Docker Compose
|
|
docker-compose up --build
|
|
|
|
# Visit: http://localhost:8080
|
|
```
|
|
|
|
---
|
|
|
|
## 📝 Next Steps
|
|
|
|
1. Configure secrets in Gitea (step 1)
|
|
2. Create Portainer stack (step 2)
|
|
3. Add webhook URL to Gitea secrets
|
|
4. Push any commit to main → CI/CD runs automatically!
|
|
|
|
---
|
|
|
|
## 🔍 Monitor CI/CD
|
|
|
|
- **Actions**: https://gitlab.impresion3d.pro/root/davidaragon-portfolio/actions
|
|
- **Registry**: https://gitlab.impresion3d.pro/root/-/packages/container/davidaragon-portfolio
|
|
- **Portainer**: http://192.168.1.30:9000/#!/stacks
|