update deploy ga #107
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
# Source : | |
# https://dev.to/ken_mwaura1/automate-docker-image-builds-and-push-to-github-registry-using-github-actions-4h20 | |
# https://docs.github.com/en/actions/publishing-packages/publishing-docker-images | |
name: Fajar Discord Bot | |
on: | |
workflow_dispatch: | |
push: | |
branches: | |
- master | |
env: | |
REGISTRY: ghcr.io | |
IMAGE_NAME: fajar-islami/fajar_discord_bot | |
CONTAINER_NAME: fajar_discord_bot | |
jobs: | |
build-image: | |
name: Build Docker Image | |
runs-on: ubuntu-latest | |
permissions: | |
contents: read | |
packages: write | |
attestations: write | |
id-token: write | |
# outputs: | |
# tagimg: ${{ steps.push.outputs.zz }} | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v2 | |
- name: Log in to the Container registry | |
if: github.event_name != 'pull_request' | |
uses: docker/login-action@65b78e6e13532edd9afa3aa52ac7964289d1a9c1 | |
with: | |
registry: ${{ env.REGISTRY }} | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
# - name: Extract metadata (tags, labels) for Docker | |
# id: meta | |
# uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7 | |
# with: | |
# images: ${{ github.sha }} | |
- name: Build and push Docker images | |
id: push | |
uses: docker/build-push-action@v6 | |
with: | |
context: . | |
push: ${{ github.event_name != 'pull_request' }} # Don't push on PR | |
tags: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ github.sha }} | |
# labels: ${{ steps.meta.outputs.labels }} | |
# - name: Generate artifact attestation | |
# uses: actions/attest-build-provenance@v1 | |
# with: | |
# subject-name: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME}} | |
# subject-digest: ${{ steps.push.outputs.digest }} | |
# push-to-registry: true | |
deploy: | |
name: Deploy app | |
needs: | |
- build-image | |
runs-on: ubuntu-latest | |
steps: | |
- name: Deploy using ssh | |
uses: appleboy/ssh-action@master | |
with: | |
host: ${{ secrets.SSH_HOST }} | |
username: ${{ secrets.SSH_USERNAME }} | |
key: ${{ secrets.SSH_PRIVATE_KEY }} | |
port: 2221 | |
script: | | |
set -e | |
cd ~/documents/ | |
date >> test.md | |
echo "tagimg ${{ needs.build-image.outputs.tagimg }} " >> test.md | |
docker login ${{env.REGISTRY}} -u ${{github.actor}} -p ${{secrets.GITHUB_TOKEN}} | |
docker pull ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ github.sha }} | |
echo ${{ vars.ENV }} > .env | |
docker ps -a --filter "ancestor=${{ env.CONTAINER_NAME }}" --format "{{.ID}}" | xargs -r docker rm | |
# echo ${{ env.CONTAINER_NAME }}_${{ github.sha }} | |
# docker run --add-host=host.docker.internal:host-gateway --name ${{ env.CONTAINER_NAME }}_${{ github.sha }} -v ./.env:/app/.env -d --restart=on-failure:5 ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ github.sha }} | |
# docker images --format "{{.Repository}}:{{.Tag}}" | grep "^${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}" | grep -v ":${{ github.sha }}" | xargs -r docker rmi | |
# docker login ${{env.REGISTRY}} -u ${{github.actor}} -p ${{secrets.GITHUB_TOKEN}} | |
# docker info | |
# echo ${{ jobs.steps.meta.outputs.labels }} | |
# echo ${{ steps.build-image.meta.outputs.labels }} | |
# deploy: | |
# name: Deploy app | |
# needs: | |
# - build-binary | |
# # - build-image | |
# runs-on: ubuntu-latest | |
# steps: | |
# - uses: actions/checkout@v3 | |
# - uses: superfly/flyctl-actions/setup-flyctl@master | |
# - run: flyctl deploy --remote-only | |
# env: | |
# FLY_API_TOKEN: ${{ secrets.FLY_API_TOKEN }} |