Skip to content

feat: add workflow for push docker image #6

feat: add workflow for push docker image

feat: add workflow for push docker image #6

Workflow file for this run

name: DEPLOY-CI
on:
push:
branches:
- master
pull_request:
branches:
- master
jobs:
build-and-push:
name: "Build and Push Image"
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Generate sha
id: generate_sha
run: |
SHA=$(echo $GITHUB_SHA | head -c7)
echo "sha=$SHA" >> "$GITHUB_OUTPUT"
- name: Build docker image
run: docker build -t devhatt/discord-bot:${{steps.generate_sha.outputs.sha}} .
- name: Log into the container registry
uses: docker/login-action@v3
with:
username: ${{secrets.DOCKER_HUB_USERNAME}}
password: ${{secrets.DOCKER_HUB_PASSWORD}}
- name: Push Image
run: |
docker push devhatt/discord-bot:${{steps.generate_sha.outputs.sha}}
docker tag devhatt/discord-bot:${{steps.generate_sha.outputs.sha}} devhatt/discord-bot:latest
docker push devhatt/discord-bot:latest
deploy:
needs: build-and-push
runs-on: self-hosted
steps:
- name: Generate sha
id: generate_sha
run: |
SHA=$(echo $GITHUB_SHA | head -c7)
echo "sha=$SHA" >> "$GITHUB_OUTPUT"
- name: Pull ima from docker hub
run: docker pull devhatt/discord-bot:${{steps.generate_sha.outputs.sha}}
- name: Remove all docker containers
run: docker rm -f $(docker ps -q)
- name: Run docker container
run: |
docker run -d --restart=always
-e DISCORD_TOKEN='${{ secrets.DISCORD_TOKEN }}'
-e CLIENT_ID='${{ secrets.CLIENT_ID }}'
-e DISCORD_SERVER_ID='${{ secrets.DISCORD_SERVER_ID }}'
-e DISCORD_CHANNEL='${{ secrets.DISCORD_CHANNEL }}'
-e DISCORD_PETDEX_ROLE='${{ secrets.DISCORD_PETDEX_ROLE }}'
-e DISCORD_OCTOPOST_ROLE='${{ secrets.DISCORD_OCTOPOST_ROLE }}'
-e DISCORD_OCTOPOST_CHANNEL='${{ secrets.DISCORD_OCTOPOST_CHANNEL }}'
-e DISCORD_PETDEX_CHANNEL='${{ secrets.DISCORD_PETDEX_CHANNEL }}'
-e CLASS_VIDEOS='${{ secrets.CLASS_VIDEOS }}'
-e NOTION_TOKEN='${{ secrets.NOTION_TOKEN }}'
-e NOTION_DATABASE_ID='${{ secrets.NOTION_DATABASE_ID }}'
--name discord-bot-c1 devhatt/discord-bot:${{steps.generate_sha.outputs.sha}}