-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: implement SSH-based deployment workflow using GitHub Actions
- Loading branch information
Showing
1 changed file
with
22 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,29 +27,29 @@ jobs: | |
- name: Build Nuxt.js app | ||
run: npm run build | ||
|
||
deploy: | ||
deploy: | ||
runs-on: ubuntu-latest | ||
needs: build | ||
steps: | ||
- name: Set up SSH | ||
uses: webfactory/[email protected] | ||
with: | ||
ssh-private-key: ${{ secrets.SSH_PRIVATE_KEY }} | ||
|
||
- name: Add server to known_hosts | ||
run: ssh-keyscan -H ${{ secrets.SERVER_IP }} >> ~/.ssh/known_hosts | ||
|
||
- name: Compress Files | ||
run: tar -czvf deploy.tar.gz --exclude='./node_modules' --exclude='./.git' --warning=no-file-changed . | ||
- name: Checkout repository | ||
uses: actions/checkout@v3 | ||
|
||
- name: Copy Tarball via SCP | ||
run: scp deploy.tar.gz ${{ secrets.SERVER_USER }}@${{ secrets.SERVER_IP }}:${{ secrets.SERVER_DEPLOY_PATH }} | ||
|
||
- name: Extract Tarball on Server | ||
- name: Set up SSH key | ||
run: | | ||
mkdir -p ~/.ssh | ||
echo "${{ secrets.ARTIFACT_SSH_KEY }}" > ~/.ssh/id_rsa | ||
chmod 600 ~/.ssh/id_rsa | ||
ssh-keyscan -p 22 ${{ secrets.HOST }} >> ~/.ssh/known_hosts | ||
sudo apt-get update | ||
sudo apt-get install -y sshpass | ||
- name: Deploy to server | ||
run: | | ||
ssh ${{ secrets.SERVER_USER }}@${{ secrets.SERVER_IP }} << 'EOF' | ||
cd ${{ secrets.SERVER_DEPLOY_PATH }} | ||
tar -xzf deploy.tar.gz | ||
rm deploy.tar.gz | ||
sudo docker-compose up -d --build | ||
EOF | ||
sshpass -p '${{ secrets.PSWD }}' ssh -o StrictHostKeyChecking=no ${{ secrets.USER }}@${{ secrets.HOST }} << 'ENDSSH' | ||
cd ${{ secrets.APP_PATH }} | ||
git pull origin main | ||
docker stop ${{ secrets.APP_NAME }} || true | ||
docker rm ${{ secrets.APP_NAME }} || true | ||
docker system prune -f | ||
docker build -t ${{ secrets.APP_NAME }} . | ||
docker run --name ${{ secrets.APP_NAME }} -d -p ${{ secrets.APP_PORT }}:${{ secrets.APP_PORT }} ${{ secrets.APP_NAME }} | ||
ENDSSH |