forked from vlourme/yahoo-auction-alert-discord-bot
-
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.
add: github actions deployment workflow
- Loading branch information
1 parent
38e4b31
commit 948c3f2
Showing
1 changed file
with
80 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,80 @@ | ||
name: Docker Build and Deploy | ||
|
||
on: | ||
push: | ||
branches: [reminders] | ||
|
||
env: | ||
APP_NAME: yahoo-auction-discord-alert-bot | ||
IMAGE_NAME: ghcr.io/${{ github.repository_owner }}/yahoo-auction-discord-alert-bot:${{ github.sha }} | ||
|
||
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: ${{ env.IMAGE_NAME }} | ||
|
||
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: ${{ env.IMAGE_NAME }} | ||
APP: ${{ env.APP_NAME }} | ||
SERVER_HOST: ${{ secrets.SERVER_HOST }} | ||
SERVER_USER: ${{ secrets.SERVER_USER }} | ||
JUMP_HOST: ${{ secrets.JUMP_HOST }} | ||
JUMP_USER: ${{ secrets.JUMP_USER }} | ||
- name: Deploy to Server | ||
env: | ||
IMAGE: ${{ env.IMAGE_NAME }} | ||
APP: ${{ env.APP_NAME }} | ||
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' | ||
set -e | ||
IMAGE="${{ env.IMAGE }}" | ||
APP="${{ env.APP }}" | ||
echo "Pulling the latest image: $IMAGE" | ||
docker pull "$IMAGE" | ||
echo "Stopping existing container if it exists" | ||
docker stop "$APP" || true | ||
echo "Removing existing container if it exists" | ||
docker rm "$APP" || true | ||
echo "Running new container" | ||
docker run -d --name "$APP" -p 80:80 "$IMAGE" | ||
ENDSSH |