Skip to content

Change Deploy yml files #9

Change Deploy yml files

Change Deploy yml files #9

Workflow file for this run

name: Deploy Next.js application
on:
push:
branches:
- main
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout Source
uses: actions/checkout@v4
- name: Create .env file
run: |
echo "PRODUCT_RUN=${{ secrets.PRODUCT_RUN }}" >> .env
- name: Archive .env file
run: tar -czf env.tar.gz .env
- name: Build Docker image
run: docker build -t prominhaj/prominhaj-portfolio .
- name: Login to Docker Hub
run: echo ${{ secrets.DOCKER_PASSWORD }} | docker login -u ${{ secrets.DOCKER_USERNAME }} --password-stdin
- name: Publish image to Docker Hub
run: docker push prominhaj/prominhaj-portfolio:latest
- name: Upload environment file
uses: actions/upload-artifact@v3
with:
name: env-file
path: env.tar.gz
deploy:
needs: build
runs-on: self-hosted
steps:
- name: Download environment file
uses: actions/download-artifact@v3
with:
name: env-file
path: .
- name: Extract environment file
run: tar -xzf env.tar.gz
- name: Check Disk Space
run: df -h
- name: Stop and remove old container if exists
run: |
if [ $(docker ps -q -f name=prominhaj-portfolio-container) ]; then
docker stop prominhaj-portfolio-container
docker rm prominhaj-portfolio-container
fi
- name: Remove old Docker images
run: |
docker rmi -f $(docker images -q)
- name: Free up Docker space
run: |
docker system prune -af
docker volume prune -f
- name: Pull image from Docker Hub
run: docker pull prominhaj/prominhaj-portfolio:latest
- name: Run Docker container
run: docker run -d -p 3000:3000 --env-file .env --name prominhaj-portfolio-container prominhaj/prominhaj-portfolio:latest