Skip to content

Commit

Permalink
add: github actions deployment workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
koenvdheuvel committed Aug 16, 2024
1 parent 38e4b31 commit 92465a4
Showing 1 changed file with 57 additions and 0 deletions.
57 changes: 57 additions & 0 deletions .github/workflows/deployment.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
name: Docker Build and Deploy

on:
push:
branches: [reminders]

jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build and Push Docker Image
uses: docker/build-push-action@v5
with:
context: .
push: true
tags: ghcr.io/${{ github.repository_owner }}/my-app:${{ github.sha }}

deploy:
runs-on: ubuntu-latest
needs: build
steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Copy SSH Key
uses: shimataro/ssh-key-action@v2
with:
key: ${{ secrets.SSH_PRIVATE_KEY }}
known_hosts: ${{ secrets.KNOWN_HOSTS }}

- name: Deploy to Server
env:
IMAGE: ghcr.io/${{ github.repository_owner }}/yahoo-auction-alert-discord-bot:${{ github.sha }}
SERVER_HOST: ${{ secrets.SERVER_HOST }}
SERVER_USER: ${{ secrets.SERVER_USER }}
JUMP_HOST: ${{ secrets.JUMP_HOST }}
JUMP_USER: ${{ secrets.JUMP_USER }}
run: |
ssh -o StrictHostKeyChecking=no -J $JUMP_USER@$JUMP_HOST $SERVER_USER@$SERVER_HOST << 'ENDSSH'
docker pull $IMAGE
docker stop yahoo-auction-alert-discord bot || true
docker rm yahoo-auction-alert-discord-bot || true
docker run -d --name -v /home/local/yahoo-auction-alert-discord-bot/alerts.db:/app/alerts.db -v /home/local/yahoo-auction-alert-discord-bot/.env:/app/.env $IMAGE
ENDSSH

0 comments on commit 92465a4

Please sign in to comment.