This repository has been archived by the owner on Feb 18, 2024. It is now read-only.
forked from bistaastha/badging-bot
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
23 additions
and
44 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 |
---|---|---|
|
@@ -7,8 +7,7 @@ on: | |
pull_request: | ||
|
||
env: | ||
REGISTRY: "registry.digitalocean.com/event-badging-bot" | ||
IMAGE_NAME: "badging" | ||
IMAGE_NAME: "event_badging" | ||
|
||
jobs: | ||
build: | ||
|
@@ -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/[email protected] | ||
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/[email protected] | ||
with: | ||
host: ${{ secrets.HOST }} | ||
|
@@ -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/[email protected] | ||
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 }} |