Refactor code

This commit is contained in:
Murtadha 2024-07-27 17:36:15 -04:00
parent 8d292b4ff7
commit 813e5afdd2

View file

@ -1,119 +1,87 @@
steps:
build:
image: node:22
commands:
- npm ci
- npm run build
- echo "VERSION=$(cat version.txt)" > .env
---
version: "3.8"
clear-from-host:
image: appleboy/drone-ssh
settings:
host:
from_secret: ssh_host
username:
from_secret: ssh_username
key:
from_secret: ssh_key
port: 2332
script:
- rm -rf /home/mnisyif/docker-containers/mnisyif/frontend/*
- echo "Target directory cleared"
services:
woodpecker-gitea:
container_name: woodpecker-gitea
image: gitea/gitea:${GITEA_VERSION:-1.14.5}
restart: unless-stopped
cpus: 0.5
mem_limit: 512m
networks:
- woodpecker
environment:
- APP_NAME="Gitea"
- USER_UID=116
- USER_GID=126
- USER=git
- RUN_MODE=prod
- DOMAIN=git.nisyif.com
- SSH_DOMAIN=git.nisyif.com
- HTTP_PORT=3000
- ROOT_URL=https://git.nisyif.com
- SSH_PORT=2121
- SSH_LISTEN_PORT=22
- DB_TYPE=sqlite3
- GIT_SSL_NO_VERIFY=true
ports:
- "2121:22"
- "3000:3000"
volumes:
- /mnt/fam_storage/Home/Git/data/gitea:/data
- /etc/timezone:/etc/timezone:ro
- /etc/localtime:/etc/localtime:ro
logging: *default-logging
copy-to-host:
image: appleboy/drone-scp
settings:
host:
from_secret: ssh_host
username:
from_secret: ssh_username
key:
from_secret: ssh_key
port: 2332
target: /home/mnisyif/docker-containers/mnisyif/frontend
source:
- dist/
- nginx.conf
- version.txt
woodpecker-server:
image: woodpeckerci/woodpecker-server:latest
container_name: woodpecker-server
restart: unless-stopped
cpus: 0.5
mem_limit: 512m
networks:
- woodpecker
environment:
- WOODPECKER_OPEN=true
- WOODPECKER_HOST=https://ci.nisyif.com
- WOODPECKER_AGENT_SECRET=${WOODPECKER_AGENT_SECRET}
- WOODPECKER_GITEA=true
- WOODPECKER_GITEA_URL=https://git.nisyif.com
- WOODPECKER_GITEA_CLIENT=${WOODPECKER_GITEA_CLIENT}
- WOODPECKER_GITEA_SECRET=${WOODPECKER_GITEA_SECRET}
- WOODPECKER_GITEA_SKIP_VERIFY=true
volumes:
- /mnt/fam_storage/Home/Git/data/server:/var/lib/woodpecker
ports:
- 8050:8000
logging: *default-logging
webserver-deploy:
image: appleboy/drone-ssh
settings:
host:
from_secret: ssh_host
username:
from_secret: ssh_username
key:
from_secret: ssh_key
port: 2332
script:
- cd /home/mnisyif/docker-containers/mnisyif/frontend
- VERSION=$(cat version.txt)
- echo "Nginx configuration:"
- cat nginx.conf
- echo "Contents of dist directory:"
- ls -la dist
# Stop and remove the existing container if it exists
- docker stop frontend || true
- docker rm frontend || true
# Run the new container with the current version, mounting the files
- >
docker run -d --name frontend -p 5173:80
-v /home/mnisyif/docker-containers/mnisyif/frontend/dist:/usr/share/nginx/html:ro
-v /home/mnisyif/docker-containers/mnisyif/frontend/nginx.conf:/etc/nginx/nginx.conf:ro
nginx:alpine
# Tag the running container with the version
- docker tag nginx:alpine frontend:$VERSION
- echo "Deployment completed"
woodpecker-agent:
image: woodpeckerci/woodpecker-agent:latest
container_name: woodpecker-agent
command: agent
restart: unless-stopped
cpus: 0.5
mem_limit: 512m
depends_on:
- woodpecker-server
networks:
- woodpecker
environment:
- WOODPECKER_SERVER=woodpecker-server:9000
- WOODPECKER_AGENT_SECRET=${WOODPECKER_AGENT_SECRET}
volumes:
- /var/run/docker.sock:/var/run/docker.sock
logging: *default-logging
confirm-deployment:
image: appleboy/drone-ssh
settings:
host:
from_secret: ssh_host
username:
from_secret: ssh_username
key:
from_secret: ssh_key
port: 2332
script:
- echo "Verifying deployment..."
# Verify the container is running
- docker ps | grep frontend || { echo "Container failed to start"; exit 1; }
# Display container logs and test nginx configuration
- docker logs frontend
- docker exec frontend nginx -t
- docker exec frontend ps aux | grep nginx
networks:
woodpecker:
name: woodpecker-net
# Check contents of /usr/share/nginx/html in the container
- docker exec frontend ls -la /usr/share/nginx/html
# Perform a simple HTTP request to check if the server is responding
- curl -I http://localhost:5173 || { echo "HTTP request failed"; exit 1; }
- echo "Deployment confirmed successfully"
cleanup:
image: appleboy/drone-ssh
settings:
host:
from_secret: ssh_host
username:
from_secret: ssh_username
key:
from_secret: ssh_key
port: 2332
script:
- echo "Performing cleanup..."
# Clean up unused containers, images, and volumes
- docker system prune -f --volumes
# Remove older versions of the Docker image
- >
for img in $(docker images frontend --format "{{.Tag}}" | grep -v $(cat /home/mnisyif/docker-containers/mnisyif/frontend/version.txt)); do
docker rmi frontend:$img || true;
done
- echo "Cleanup completed"
trigger:
event:
- push
branch:
- master
x-logging:
&default-logging
driver: "json-file"
options:
max-size: "1m"
max-file: "1"
tag: "{{.Name}}"