Refactor some lines
This commit is contained in:
parent
88b5743bb7
commit
e0679b4582
1 changed files with 112 additions and 113 deletions
225
.woodpecker.yml
225
.woodpecker.yml
|
|
@ -1,120 +1,119 @@
|
||||||
pipeline:
|
pipeline:
|
||||||
build:
|
build:
|
||||||
image: node:22
|
image: node:22
|
||||||
commands:
|
commands:
|
||||||
- npm ci
|
- npm ci
|
||||||
- npm run build
|
- npm run build
|
||||||
- echo "VERSION=$(cat version.txt)" > .env
|
- echo "VERSION=$(cat version.txt)" > .env
|
||||||
|
|
||||||
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"
|
|
||||||
|
|
||||||
copy-to-host:
|
clear-from-host:
|
||||||
image: appleboy/drone-scp
|
image: appleboy/drone-ssh
|
||||||
settings:
|
settings:
|
||||||
host:
|
host:
|
||||||
from_secret: ssh_host
|
from_secret: ssh_host
|
||||||
username:
|
username:
|
||||||
from_secret: ssh_username
|
from_secret: ssh_username
|
||||||
key:
|
key:
|
||||||
from_secret: ssh_key
|
from_secret: ssh_key
|
||||||
port: 2332
|
port: 2332
|
||||||
target: /home/mnisyif/docker-containers/mnisyif/frontend
|
script:
|
||||||
source:
|
- rm -rf /home/mnisyif/docker-containers/mnisyif/frontend/*
|
||||||
- dist/
|
- echo "Target directory cleared"
|
||||||
- nginx.conf
|
|
||||||
- version.txt
|
|
||||||
|
|
||||||
webserver-deploy:
|
copy-to-host:
|
||||||
image: appleboy/drone-ssh
|
image: appleboy/drone-scp
|
||||||
settings:
|
settings:
|
||||||
host:
|
host:
|
||||||
from_secret: ssh_host
|
from_secret: ssh_host
|
||||||
username:
|
username:
|
||||||
from_secret: ssh_username
|
from_secret: ssh_username
|
||||||
key:
|
key:
|
||||||
from_secret: ssh_key
|
from_secret: ssh_key
|
||||||
port: 2332
|
port: 2332
|
||||||
script:
|
target: /home/mnisyif/docker-containers/mnisyif/frontend
|
||||||
- cd /home/mnisyif/docker-containers/mnisyif/frontend
|
source:
|
||||||
- VERSION=$(cat version.txt)
|
- dist/
|
||||||
- echo "Nginx configuration:"
|
- nginx.conf
|
||||||
- cat nginx.conf
|
- version.txt
|
||||||
- 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"
|
|
||||||
|
|
||||||
confirm-deployment:
|
webserver-deploy:
|
||||||
image: appleboy/drone-ssh
|
image: appleboy/drone-ssh
|
||||||
settings:
|
settings:
|
||||||
host:
|
host:
|
||||||
from_secret: ssh_host
|
from_secret: ssh_host
|
||||||
username:
|
username:
|
||||||
from_secret: ssh_username
|
from_secret: ssh_username
|
||||||
key:
|
key:
|
||||||
from_secret: ssh_key
|
from_secret: ssh_key
|
||||||
port: 2332
|
port: 2332
|
||||||
script:
|
script:
|
||||||
- echo "Verifying deployment..."
|
- cd /home/mnisyif/docker-containers/mnisyif/frontend
|
||||||
# Verify the container is running
|
- VERSION=$(cat version.txt)
|
||||||
- docker ps | grep frontend || { echo "Container failed to start"; exit 1; }
|
- echo "Nginx configuration:"
|
||||||
# Display container logs
|
- cat nginx.conf
|
||||||
- docker logs frontend
|
- echo "Contents of dist directory:"
|
||||||
# Test Nginx configuration
|
- ls -la dist
|
||||||
- docker exec frontend nginx -t
|
# Stop and remove the existing container if it exists
|
||||||
# Check Nginx process
|
- docker stop frontend || true
|
||||||
- docker exec frontend ps aux | grep nginx
|
- docker rm frontend || true
|
||||||
# Check contents of /usr/share/nginx/html in the container
|
# Run the new container with the current version, mounting the files
|
||||||
- docker exec frontend ls -la /usr/share/nginx/html
|
- >
|
||||||
# Perform a simple HTTP request to check if the server is responding
|
docker run -d --name frontend -p 5173:80
|
||||||
- curl -I http://localhost:5173 || { echo "HTTP request failed"; exit 1; }
|
-v /home/mnisyif/docker-containers/mnisyif/frontend/dist:/usr/share/nginx/html:ro
|
||||||
- echo "Deployment confirmed successfully"
|
-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"
|
||||||
|
|
||||||
cleanup:
|
confirm-deployment:
|
||||||
image: appleboy/drone-ssh
|
image: appleboy/drone-ssh
|
||||||
settings:
|
settings:
|
||||||
host:
|
host:
|
||||||
from_secret: ssh_host
|
from_secret: ssh_host
|
||||||
username:
|
username:
|
||||||
from_secret: ssh_username
|
from_secret: ssh_username
|
||||||
key:
|
key:
|
||||||
from_secret: ssh_key
|
from_secret: ssh_key
|
||||||
port: 2332
|
port: 2332
|
||||||
script:
|
script:
|
||||||
- echo "Performing cleanup..."
|
- echo "Verifying deployment..."
|
||||||
# Clean up unused containers, images, and volumes
|
# Verify the container is running
|
||||||
- docker system prune -f --volumes
|
- docker ps | grep frontend || { echo "Container failed to start"; exit 1; }
|
||||||
# Remove older versions of the Docker image
|
# Display container logs and test nginx configuration
|
||||||
- >
|
- docker logs frontend
|
||||||
for img in $(docker images frontend --format "{{.Tag}}" | grep -v $(cat /home/mnisyif/docker-containers/mnisyif/frontend/version.txt)); do
|
- docker exec frontend nginx -t
|
||||||
docker rmi frontend:$img || true;
|
- docker exec frontend ps aux | grep nginx
|
||||||
done
|
|
||||||
- echo "Cleanup completed"
|
# 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:
|
trigger:
|
||||||
event:
|
event:
|
||||||
- push
|
- push
|
||||||
branch:
|
branch:
|
||||||
- master
|
- master
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue