This repository has been archived by the owner on Feb 18, 2024. It is now read-only.
[REFACTOR]: refactor function smee in index.js to make it more dynami… #25
Workflow file for this run
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: CI/CD | |
on: | |
push: | |
branches: | |
- "*" | |
pull_request: | |
env: | |
REGISTRY: "registry.digitalocean.com/event-badging-bot" | |
IMAGE_NAME: "badging" | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Install dependencies | |
run: npm install | |
- name: Lint code | |
run: npm run format | |
docker-build: | |
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 }} | |
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 | |
with: | |
token: ${{ secrets.DIGITALOCEAN_ACCESS_TOKEN }} | |
- name: Stop and remove existing images with the same name on the droplet | |
uses: appleboy/ssh-action@v0.1.10 | |
with: | |
host: ${{ secrets.HOST }} | |
username: ${{ secrets.USERNAME }} | |
password: ${{ secrets.PASSWORD }} | |
script: | | |
if docker inspect ${{ env.IMAGE_NAME }} >/dev/null 2>&1; then | |
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 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 }} |