Skip to content

Commit

Permalink
fix: update deployment workflows to use latest Docker tag and remove …
Browse files Browse the repository at this point in the history
…unnecessary triggers
  • Loading branch information
nestorzamili committed Feb 22, 2025
1 parent a3bfe30 commit 319db9e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 19 deletions.
15 changes: 9 additions & 6 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@ name: Deploy to VM

on:
workflow_dispatch:
workflow_run:
workflows: ["Docker Build and Push"]
types: [completed]

jobs:
deploy:
Expand All @@ -19,18 +16,24 @@ jobs:
run: |
ssh -o StrictHostKeyChecking=no -i ssh_key ${{ secrets.VM_USER }}@${{ secrets.VM_HOST }} "echo 'SSH Connection Successful!'"
- name: Get Latest Tag from Docker Hub
id: get-latest-tag
run: |
LATEST_TAG=$(curl -s "https://hub.docker.com/v2/repositories/${{ secrets.DOCKER_USERNAME }}/whatsapp-blast/tags?page_size=1" | jq -r '.results[0].name')
echo "LATEST_TAG=$LATEST_TAG" >> $GITHUB_ENV
- name: Deploy to VM
run: |
ssh -o StrictHostKeyChecking=no -i ssh_key ${{ secrets.VM_USER }}@${{ secrets.VM_HOST }} << 'EOF'
ssh -o StrictHostKeyChecking=no -i ssh_key ${{ secrets.VM_USER }}@${{ secrets.VM_HOST }} << EOF
echo "Login SSH berhasil!"
echo ${{ secrets.DOCKER_PASSWORD }} | docker login --username ${{ secrets.DOCKER_USERNAME }} --password-stdin
docker pull ${{ secrets.DOCKER_USERNAME }}/whatsapp-blast:latest
docker pull ${{ secrets.DOCKER_USERNAME }}/whatsapp-blast:$LATEST_TAG
docker stop whatsapp-blast || true
docker rm whatsapp-blast || true
docker run -d --name whatsapp-blast --restart unless-stopped \
--env-file /home/${{ secrets.VM_USER }}/whatsapp-blast/.env \
-v /home/${{ secrets.VM_USER }}/whatsapp-blast/sessions:/app/sessions \
-p 3000:3000 ${{ secrets.DOCKER_USERNAME }}/whatsapp-blast:latest
-p 3000:3000 ${{ secrets.DOCKER_USERNAME }}/whatsapp-blast:$LATEST_TAG
EOF
16 changes: 3 additions & 13 deletions .github/workflows/docker-build.yml
Original file line number Diff line number Diff line change
@@ -1,18 +1,11 @@
name: Docker Build and Push

on:
# workflow_run:
# workflows: ["release-please"]
# types:
# - completed
workflow_dispatch:

jobs:
docker:
runs-on: ubuntu-latest
if: >
github.event.workflow_run.conclusion == 'success' &&
github.event.workflow_run.head_branch == 'main'
steps:
- name: Checkout Repository
uses: actions/checkout@v4
Expand All @@ -25,7 +18,7 @@ jobs:
if git describe --tags --abbrev=0 > /dev/null 2>&1; then
echo "LATEST_TAG=$(git describe --tags --abbrev=0)" >> $GITHUB_ENV
else
echo "LATEST_TAG=latest" >> $GITHUB_ENV
echo "LATEST_TAG=0.0.1" >> $GITHUB_ENV # Default jika belum ada tag
fi
- name: Login to Docker Hub
Expand All @@ -39,8 +32,5 @@ jobs:
with:
context: .
push: true
tags: |
${{ secrets.DOCKER_USERNAME }}/whatsapp-blast:latest
${{ secrets.DOCKER_USERNAME }}/whatsapp-blast:${{ env.LATEST_TAG }}
build-args: |
GIT_TAG=${{ env.LATEST_TAG }}
tags: ${{ secrets.DOCKER_USERNAME }}/whatsapp-blast:${{ env.LATEST_TAG }}
build-args: GIT_TAG=${{ env.LATEST_TAG }}

0 comments on commit 319db9e

Please sign in to comment.