Skip to content

Commit

Permalink
ci: Update CI/CD workflows
Browse files Browse the repository at this point in the history
  • Loading branch information
tklein1801 committed Aug 11, 2023
1 parent 4a51836 commit 5128bbf
Show file tree
Hide file tree
Showing 3 changed files with 116 additions and 82 deletions.
35 changes: 35 additions & 0 deletions .github/workflows/deployment.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: Deploy Docker Image

on:
workflow_dispatch:
repository_dispatch:
types: [trigger_deployment]

env:
IMAGE_NAME: ghcr.io/dulliag/dulli-bot

jobs:
renew_docker_compose:
name: Rebuild Remote Docker-Compose
runs-on: ubuntu-latest
environment: production
steps:
- name: Connect and deploy
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.RS1_HOST }}
username: ${{ secrets.RS1_USER }}
password: ${{ secrets.RS1_PASSWORD }}
port: 22
script: |
echo ${{ secrets.NPM_TOKEN }} | docker login ghcr.io -u ${{ secrets.DOCKER_USER }} --password-stdin
CONTAINER_NAME="dullibot"
if [ "$(docker ps -a --filter "name=$CONTAINER_NAME" --format '{{.Names}}')" ]; then
docker container stop $CONTAINER_NAME
docker container rm -f $CONTAINER_NAME
fi
if [ "$(docker images -q "${{ env.IMAGE_NAME }}:latest")" ]; then
docker rmi "${{ env.IMAGE_NAME }}:latest"
fi
docker pull ${{ env.IMAGE_NAME }}:latest
docker run -itd --env-file '${{ secrets.RS1_REMOTE_LOCATION }}/dullibot.env' --restart on-failure:3 --name=$CONTAINER_NAME ${{ env.IMAGE_NAME }}:latest
82 changes: 0 additions & 82 deletions .github/workflows/main.yml

This file was deleted.

81 changes: 81 additions & 0 deletions .github/workflows/publish_docker_image.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
name: Build & Publish Docker Image

on:
workflow_dispatch:
push:
tags:
- 'v[0-9]+.[0-9]+.[0-9]+'

env:
IMAGE_NAME: ghcr.io/dulliag/dulli-bot

jobs:
build_image:
name: Build Docker Image
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Build Image
run: |
rm .npmrc
echo $'@kleithor:registry=https://npm.pkg.github.com\n//npm.pkg.github.com/:_authToken='$NPM_TOKEN >> .npmrc
docker build --secret id=npm,src=.npmrc . -t ${{ env.IMAGE_NAME }}:${{ github.ref_name }}
mkdir -p artifacts
docker save ${{ env.IMAGE_NAME }}:${{ github.ref_name }} > artifacts/docker-image.tar
env:
DOCKER_BUILDKIT: 1
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}

- name: Save Image
uses: actions/upload-artifact@v2
with:
name: docker-artifact
path: artifacts
retention-days: 1

push_image:
needs: build_image
name: Push Docker Image
runs-on: ubuntu-latest
steps:
- name: Retrieve Docker Image
uses: actions/download-artifact@v2
with:
name: docker-artifact
path: artifacts

- name: Load Image
run: |
cd artifacts
docker load < docker-image.tar
- name: Login
run: |
echo ${{ secrets.NPM_TOKEN }} | docker login ghcr.io -u ${{ secrets.DOCKER_USER }} --password-stdin
- name: Push Image
run: |
docker push ${{ env.IMAGE_NAME }}:${{ github.ref_name }}
docker tag ${{ env.IMAGE_NAME }}:${{ github.ref_name }} ${{ env.IMAGE_NAME }}:latest
docker push ${{ env.IMAGE_NAME }}:latest
trigger_deployment:
needs: push_image
name: Trigger deployment
runs-on: ubuntu-latest
steps:
- name: Dispatch
uses: peter-evans/repository-dispatch@v2
with:
token: ${{ secrets.NPM_TOKEN }}
event-type: trigger_deployment

cleanup:
needs: push_image
name: Cleanup
runs-on: ubuntu-latest
steps:
- name: Delete Artifact
uses: geekyeggo/delete-artifact@v1
with:
name: docker-artifact

0 comments on commit 5128bbf

Please sign in to comment.