Skip to content

Merge pull request #6 from badging:api-fixes #18

Merge pull request #6 from badging:api-fixes

Merge pull request #6 from badging:api-fixes #18

Workflow file for this run

name: CI/CD
on:
push:
branches:
- "*"
pull_request:
env:
REGISTRY: "registry.digitalocean.com/badging"
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
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 Docker image
run: docker build -t ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ github.sha }} .
- name: Push Docker image to DigitalOcean Droplet
uses: appleboy/[email protected]
with:
host: ${{ secrets.HOST }}
username: ${{ secrets.USERNAME }}
password: ${{ secrets.PASSWORD }}
script: |
docker stop ${{ env.IMAGE_NAME }} || true
docker rm ${{ env.IMAGE_NAME }} || true
docker rmi ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ github.sha }} || true
docker load -i - << '${{ runner.workspace }}/.image.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 }}