Skip to content

updated the steps order #3

updated the steps order

updated the steps order #3

Workflow file for this run

name: Deploys Solana Project to Ubuntu VPS
on:
push:
branches:
- main
jobs:
prepare_environment:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Esure target directory exists on VPS
uses: appleboy/ssh-action@v0.1.3
with:
host: ${{ secrets.SSH_HOST }}
username: ${{ secrets.SSH_USERNAME }}
key: ${{ secrets.SSH_PRIVATE_KEY }}
script: |
if [ ! -d "/dockerized/containers/solana_project" ]; then
mkdir -p /dockerized/containers/solana_project
else
rm -rf /dockerized/containers/solana_project/*
fi
- name: Copy Github files to VPS
uses: appleboy/scp-action@v0.1.3
with:
host: ${{ secrets.SSH_HOST }}
username: ${{ secrets.SSH_USERNAME }}
key: ${{ secrets.SSH_PRIVATE_KEY }}
source: "./"
target: "/dockerized/containers/solana_project"
- name: Create .env file
uses: appleboy/ssh-action@v0.1.3
with:
host: ${{ secrets.SSH_HOST }}
username: ${{ secrets.SSH_USERNAME }}
key: ${{ secrets.SSH_PRIVATE_KEY }}
script: |
cat << EOF > /dockerized/containers/solana_project/.env
NEXT_PUBLIC_TOKEN_OWNER_KEY_PAIR=${{ secrets.NEXT_PUBLIC_TOKEN_OWNER_KEY_PAIR }}
EOF
build_docker_image:
needs: prepare_environment
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Build Docker image with commit hash
uses: appleboy/ssh-action@v0.1.3
with:
host: ${{ secrets.SSH_HOST }}
username: ${{ secrets.SSH_USERNAME }}
key: ${{ secrets.SSH_PRIVATE_KEY }}
script: |
export DOCKER_BUILDKIT=1
cd /dockerized/containers/solana_project
docker build -t solana_project_image .
stop_and_start_container:
needs: build_docker_image
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Stop and remove old Docker containers
uses: appleboy/ssh-action@v0.1.3
with:
host: ${{ secrets.SSH_HOST }}
username: ${{ secrets.SSH_USERNAME }}
key: ${{ secrets.SSH_PRIVATE_KEY }}
script: |
docker stop solana_project_instance || true
docker rm solana_project_instance || true
- name: Run new Docker container
uses: appleboy/ssh-action@v0.1.3
with:
host: ${{ secrets.SSH_HOST }}
username: ${{ secrets.SSH_USERNAME }}
key: ${{ secrets.SSH_PRIVATE_KEY }}
script: |
docker run -d --name solana_project_instance --restart unless-stopped -p ${{secrets.PORT}}:3000 -v solana_project_volume:/data solana_project_image
clean_up_except_the_latest:
needs: stop_and_start_container
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Clean up previous Docker images except the latest
uses: appleboy/ssh-action@v0.1.3
with:
host: ${{ secrets.SSH_HOST }}
username: ${{ secrets.SSH_USERNAME }}
key: ${{ secrets.SSH_PRIVATE_KEY }}
script: |
# Get the latest image ID
latest_image_id=$(docker images 'solana_project_image*' --format "{{.ID}}" | head -n1)
# Remove all images except the latest one
docker images 'solana_project_image*' --format "{{.ID}}" | grep -v "$latest_image_id" | xargs --no-run-if-empty docker rmi
- name: Remove untagged Docker images
uses: appleboy/ssh-action@v0.1.3
with:
host: ${{ secrets.SSH_HOST }}
username: ${{ secrets.SSH_USERNAME }}
key: ${{ secrets.SSH_PRIVATE_KEY }}
script: |
docker rmi $(docker images -f "dangling=true" -q) || true