Skip to content

added a GH action for VPS deployment #1

added a GH action for VPS deployment

added a GH action for VPS deployment #1

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/[email protected]
with:
host: ${{ SSH_HOST }}

Check failure on line 17 in .github/workflows/main.yml

View workflow run for this annotation

GitHub Actions / Deploys Solana Project to Ubuntu VPS

Invalid workflow file

The workflow is not valid. .github/workflows/main.yml (Line: 17, Col: 17): Unrecognized named-value: 'SSH_HOST'. Located at position 1 within expression: SSH_HOST .github/workflows/main.yml (Line: 18, Col: 21): Unrecognized named-value: 'SSH_USERNAME'. Located at position 1 within expression: SSH_USERNAME
username: ${{ SSH_USERNAME }}
key: ${{ 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/[email protected]
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/[email protected]
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:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Build Docker image with commit hash
uses: appleboy/[email protected]
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/[email protected]
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/[email protected]
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/[email protected]
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/[email protected]
with:
host: ${{ secrets.SSH_HOST }}
username: ${{ secrets.SSH_USERNAME }}
key: ${{ secrets.SSH_PRIVATE_KEY }}
script: |
docker rmi $(docker images -f "dangling=true" -q) || true