Deploy Docker with bash file #107
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
name: Deploy Docker with bash file | |
on: | |
workflow_run: | |
workflows: | |
- 'Build and push Docker' | |
types: | |
- completed | |
workflow_dispatch: | |
env: | |
SSH_ALIAS: arm1 | |
IMAGE_NAME_WITH_TAG: ${{ secrets.DOCKER_USERNAME }}/${{ github.event.repository.name }}:latest | |
jobs: | |
deploy: | |
name: Deploy image from Dockerhub to remote host with ssh | |
runs-on: ubuntu-latest | |
if: ${{ github.event.workflow_run.conclusion == 'success' }} | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 1 | |
- name: Set up Node.js and Yarn for yarn command | |
uses: actions/setup-node@v4 | |
with: | |
node-version: '22.9.0' | |
registry-url: 'https://registry.yarnpkg.com' | |
- name: Set up SSH config | |
run: | | |
# Set up SSH key | |
mkdir -p ~/.ssh | |
echo "${{ secrets.REMOTE_KEY_ED25519 }}" > ~/.ssh/id_ed25519 | |
chmod 600 ~/.ssh/id_ed25519 | |
# Set up SSH config | |
echo "Host $SSH_ALIAS" > ~/.ssh/config | |
echo " HostName ${{ secrets.REMOTE_HOST }}" >> ~/.ssh/config | |
echo " User ${{ secrets.REMOTE_USERNAME }}" >> ~/.ssh/config | |
echo " IdentityFile ~/.ssh/id_ed25519" >> ~/.ssh/config | |
echo " Port ${{ secrets.REMOTE_PORT }}" >> ~/.ssh/config | |
chmod 600 ~/.ssh/config | |
# Add SSH server key to known_hosts | |
ssh-keyscan -H ${{ secrets.REMOTE_HOST }} >> ~/.ssh/known_hosts | |
- name: Run bash file with yarn | |
run: yarn deploy:docker |