Add versioning feature

This commit is contained in:
Murtadha 2024-07-14 01:20:12 -04:00
parent 3a30900757
commit 5e3ef11dd5
2 changed files with 63 additions and 4 deletions

View file

@ -1,3 +1,50 @@
# pipeline:
# build:
# image: node:22
# commands:
# - npm ci
# - npm run build
# when:
# branch: master
# ssh-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/
# - Dockerfile
# - nginx.conf
# when:
# branch: master
# webserver-docker-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
# - docker build -t frontend:${CI_COMMIT_SHA} .
# - docker stop frontend || true
# - docker rm frontend || true
# - docker run -d --name frontend -p 5173:80 frontend:${CI_COMMIT_SHA}
# - docker image prune -f # Remove dangling images
# - docker system prune -f --volumes # Clean up unused containers, images, and volumes
# when:
# branch: master
pipeline:
build:
image: node:22
@ -37,11 +84,22 @@ pipeline:
port: 2332
script:
- cd /home/mnisyif/docker-containers/mnisyif/frontend
- docker build -t frontend:${CI_COMMIT_SHA} .
- VERSION=$(cat version.txt)
# Build the new Docker image with the current version tag
- docker build -t frontend:$VERSION .
# Stop and remove the existing container if it exists
- docker stop frontend || true
- docker rm frontend || true
- docker run -d --name frontend -p 5173:80 frontend:${CI_COMMIT_SHA}
- docker image prune -f # Remove dangling images
- docker system prune -f --volumes # Clean up unused containers, images, and volumes
# Run the new container with the current version
- docker run -d --name frontend -p 5173:80 frontend:$VERSION
# Remove dangling images
- docker image prune -f
# 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 $VERSION); do
docker rmi frontend:$img;
done
when:
branch: master

1
version.txt Normal file
View file

@ -0,0 +1 @@
0.5.0