Skip to content
This repository has been archived by the owner on Feb 18, 2024. It is now read-only.

Commit

Permalink
changed deploy configs
Browse files Browse the repository at this point in the history
  • Loading branch information
kaxada committed Dec 13, 2023
1 parent d5979fc commit 71a47d8
Showing 1 changed file with 23 additions and 44 deletions.
67 changes: 23 additions & 44 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ on:
pull_request:

env:
REGISTRY: "registry.digitalocean.com/event-badging-bot"
IMAGE_NAME: "badging"
IMAGE_NAME: "event_badging"

jobs:
build:
Expand All @@ -20,41 +19,28 @@ jobs:
- name: Lint code
run: npm run format

docker-build:
deploy:
needs: build
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
steps:
- uses: actions/checkout@v3
- name: Login to DigitalOcean registry
uses: digitalocean/action-doctl@v2
with:
token: ${{ secrets.DIGITALOCEAN_ACCESS_TOKEN }}
- name: Log in to DigitalOcean Container Registry with short-lived credentials
run: doctl registry login --expiry-seconds 600
- name: Delete existing images with similar name
run: |
doctl registry repository list-tags $REGISTRY/$IMAGE_NAME --format Name --no-header |
while read -r image_tag; do
doctl registry image delete $REGISTRY/$IMAGE_NAME:$image_tag;
done
- name: Build and push Docker image
uses: docker/build-push-action@v4
with:
context: .
push: true
tags: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ github.sha }}
- name: Build Docker image
run: docker build -t ${{ env.IMAGE_NAME }}:${{ github.sha }} .

deploy:
needs: docker-build
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
steps:
- name: Login to DigitalOcean registry
uses: digitalocean/action-doctl@v2
- name: Create image archive
run: docker save ${{ env.IMAGE_NAME }}:${{ github.sha }} -o event_badging.tar

- name: Upload image archive using appleboy/scp-action
uses: appleboy/scp-action@v0.1.4
with:
token: ${{ secrets.DIGITALOCEAN_ACCESS_TOKEN }}
- name: Stop and remove existing images with the same name on the droplet
host: ${{ secrets.HOST }}
username: ${{ secrets.USERNAME }}
password: ${{ secrets.PASSWORD }}
source: event_badging.tar
target: ~/

- name: Extract and load image on droplet
uses: appleboy/ssh-action@v0.1.10
with:
host: ${{ secrets.HOST }}
Expand All @@ -65,18 +51,11 @@ jobs:
docker stop ${{ env.IMAGE_NAME }}
docker rm ${{ env.IMAGE_NAME }}
fi
- name: Deploy Docker image to DigitalOcean Droplet
uses: appleboy/ssh-action@v0.1.10
with:
host: ${{ secrets.HOST }}
username: ${{ secrets.USERNAME }}
password: ${{ secrets.PASSWORD }}
script: |
docker pull ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ github.sha }}
echo ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ github.sha }}
docker rmi -f $(docker images -q ${{ env.IMAGE_NAME }}) || true
docker load -i ~/event_badging.tar
docker run -d \
-p ${{ secrets.PORT }}:${{ secrets.PORT }} \
--env-file /home/${{ secrets.USERNAME }}/.env \
--restart=always \
--name ${{ env.IMAGE_NAME }} \
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ github.sha }}
-p ${{ secrets.PORT }}:${{ secrets.PORT }} \
--env-file /home/${{ secrets.USERNAME }}/.env.badging_bot \
--restart=always \
--name ${{ env.IMAGE_NAME }} \
${{ env.IMAGE_NAME }}:${{ github.sha }}

0 comments on commit 71a47d8

Please sign in to comment.