Skip to content

Workflow file for this run

name: Build and Deploy Docker Image on Server
on:
push
env:
SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }}
SERVER_USER: ${{ secrets.SERVER_USER }}
SERVER_HOST: ${{ secrets.SERVER_HOST }}
KNOWN_HOSTS: ${{ secrets.KNOWN_HOSTS }}
DIRECTORY: "${{ vars.DIRECTORY }}/${{ github.event.repository.name }}"
jobs:
build-and-deploy:
environment: Test
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
submodules: 'recursive'
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: "latest"
- name: Create .env file
run: |
echo "${{ secrets.ENVS }}" > .env
- name: Set up SSH
uses: webfactory/[email protected]
with:
ssh-private-key: ${{ env.SSH_PRIVATE_KEY }}
- name: Add server to known hosts
run: |
mkdir -p ~/.ssh
echo "$KNOWN_HOSTS" > ~/.ssh/known_hosts
- name: Deploy on Server
run: |
ssh -t $SERVER_USER@$SERVER_HOST << EOF
if [ -d "$DIRECTORY" ]; then
rm -rf $DIRECTORY
fi
mkdir -p $DIRECTORY
cd $DIRECTORY
git clone --recurse-submodules https://github.com/${{ github.repository }} .
echo "${{ secrets.ENVS }}" > .env
sh deploy.sh
EOF