feat: Add Woodpecker CI/CD pipeline for automated deployments and update Docker Compose to pull images from Gitea registry with .env file integration.
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
This commit is contained in:
45
.woodpecker.yml
Normal file
45
.woodpecker.yml
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
pipeline:
|
||||||
|
# 1. Build & Push Image ke Gitea Container Registry
|
||||||
|
# Kita menggunakan plugin/docker agar Woodpecker melakukan build Dockerfile Anda
|
||||||
|
build-and-push:
|
||||||
|
image: plugins/docker
|
||||||
|
settings:
|
||||||
|
# URL Gitea Anda
|
||||||
|
registry: git.exavolt.web.id
|
||||||
|
# Format: git.exavolt.web.id/username/repo-name
|
||||||
|
repo: git.exavolt.web.id/fikri/fullstack-portfolio
|
||||||
|
username:
|
||||||
|
from_secret: gitea_user
|
||||||
|
password:
|
||||||
|
from_secret: gitea_token
|
||||||
|
dockerfile: Dockerfile
|
||||||
|
# Menggunakan cache agar build berikutnya lebih cepat
|
||||||
|
use_cache: true
|
||||||
|
when:
|
||||||
|
branch: main
|
||||||
|
event: push
|
||||||
|
|
||||||
|
# 2. Deploy ke VPS via SSH
|
||||||
|
deploy:
|
||||||
|
image: appleboy/drone-ssh
|
||||||
|
settings:
|
||||||
|
host: 103.197.190.44
|
||||||
|
username: root
|
||||||
|
key:
|
||||||
|
from_secret: ssh_key
|
||||||
|
port: 22
|
||||||
|
script:
|
||||||
|
# Pindah ke folder tempat docker-compose.yml berada di VPS
|
||||||
|
- cd ~/portfolio
|
||||||
|
# Login ke Gitea Registry (diperlukan untuk pull image)
|
||||||
|
- echo $GITEA_TOKEN | docker login git.exavolt.web.id -u $GITEA_USER --password-stdin
|
||||||
|
# Tarik image terbaru yang baru saja di-build
|
||||||
|
- docker compose pull
|
||||||
|
# Restart container dengan image baru
|
||||||
|
- docker compose up -d --remove-orphans
|
||||||
|
# Membersihkan image lama yang tidak terpakai (dangling)
|
||||||
|
- docker image prune -f
|
||||||
|
secrets: [ gitea_user, gitea_token, ssh_key ]
|
||||||
|
when:
|
||||||
|
branch: main
|
||||||
|
event: push
|
||||||
@@ -1,15 +1,17 @@
|
|||||||
services:
|
services:
|
||||||
app:
|
app:
|
||||||
build:
|
# Mengambil image dari Registry Gitea Anda
|
||||||
context: .
|
image: git.exavolt.web.id/fikri/portfolio-app:latest
|
||||||
dockerfile: Dockerfile
|
|
||||||
image: fikri-portfolio-app
|
|
||||||
container_name: fikri-portfolio-app
|
container_name: fikri-portfolio-app
|
||||||
restart: always
|
restart: always
|
||||||
ports:
|
ports:
|
||||||
- "4000:4000"
|
- "4000:4000"
|
||||||
|
|
||||||
|
# Mengambil variabel dari file .env di folder yang sama
|
||||||
|
env_file:
|
||||||
|
- .env
|
||||||
|
|
||||||
environment:
|
environment:
|
||||||
# Aplikasi akan langsung menggunakan DATABASE_URL dari file .env (pointing ke DB existing Anda)
|
|
||||||
DATABASE_URL: ${DATABASE_URL}
|
DATABASE_URL: ${DATABASE_URL}
|
||||||
JWT_SECRET: ${JWT_SECRET}
|
JWT_SECRET: ${JWT_SECRET}
|
||||||
R2_TOKEN: ${R2_TOKEN}
|
R2_TOKEN: ${R2_TOKEN}
|
||||||
@@ -18,7 +20,12 @@ services:
|
|||||||
R2_ENDPOINT: ${R2_ENDPOINT}
|
R2_ENDPOINT: ${R2_ENDPOINT}
|
||||||
R2_BUCKET_NAME: ${R2_BUCKET_NAME}
|
R2_BUCKET_NAME: ${R2_BUCKET_NAME}
|
||||||
IMAGE_URL: ${IMAGE_URL}
|
IMAGE_URL: ${IMAGE_URL}
|
||||||
|
# Tambahkan port agar internal container sesuai
|
||||||
|
PORT: 4000
|
||||||
|
|
||||||
extra_hosts:
|
extra_hosts:
|
||||||
- "host.docker.internal:host-gateway"
|
- "host.docker.internal:host-gateway"
|
||||||
|
|
||||||
|
# Tetap jalankan migrasi database sebelum start
|
||||||
command: >
|
command: >
|
||||||
sh -c "npx prisma migrate deploy && node server.js"
|
sh -c "npx prisma migrate deploy && node server.js"
|
||||||
Reference in New Issue
Block a user