[DOVU Alpha V2] Guardian Middleware API rewrite (#20) #11
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 | |
# 1 | |
# Controls when the workflow will run | |
on: | |
# Triggers the workflow on push events but only for the main branch | |
push: | |
branches: [main] | |
# Allows you to run this workflow manually from the Actions tab | |
workflow_dispatch: | |
inputs: | |
version: | |
description: 'Image version' | |
required: true | |
#2 | |
env: | |
REGISTRY: 'registry.digitalocean.com/dovu' | |
IMAGE_NAME: 'guardian-middleware-api' | |
#3 | |
jobs: | |
build_and_push: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout the repo | |
uses: actions/checkout@v2 | |
- name: Build container image | |
run: docker build -t $(echo $REGISTRY)/$(echo $IMAGE_NAME):$(echo $GITHUB_SHA | head -c7) . | |
- name: Install doctl | |
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: Push image to DigitalOcean Container Registry | |
run: docker push $(echo $REGISTRY)/$(echo $IMAGE_NAME):$(echo $GITHUB_SHA | head -c7) | |
deploy: | |
runs-on: ubuntu-latest | |
needs: build_and_push | |
steps: | |
- name: Deploy to Digital Ocean droplet via SSH action | |
uses: appleboy/[email protected] | |
with: | |
host: ${{ secrets.DROPLET_HOST }} | |
username: ${{ secrets.DROPLET_USERNAME }} | |
key: ${{ secrets.DROPLET_SSH_KEY }} | |
envs: IMAGE_NAME,REGISTRY,{{ secrets.DIGITALOCEAN_ACCESS_TOKEN }},GITHUB_SHA | |
script: | | |
# Login to registry | |
docker login -u ${{ secrets.DIGITALOCEAN_ACCESS_TOKEN }} -p ${{ secrets.DIGITALOCEAN_ACCESS_TOKEN }} registry.digitalocean.com | |
# Stop running containers | |
docker compose down | |
# Set environment vars | |
DOCKER_CONTAINER_REGISTRY=$(echo $REGISTRY) | |
DOCKER_IMAGE_NAME=$(echo $IMAGE_NAME) | |
DOCKER_IMAGE_TAG=$(echo $GITHUB_SHA | head -c7) | |
export DOCKER_CONTAINER_REGISTRY | |
export DOCKER_IMAGE_NAME | |
export DOCKER_IMAGE_TAG | |
# Run a new container from a new image | |
docker compose up -d | |
# Clean out old images | |
docker image prune -af |