fix issue import #13
Workflow file for this run
This file contains hidden or 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: Build & Push Docker Image | |
on: | |
push: | |
tags: | |
- '*' | |
jobs: | |
build-and-push: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
- name: Log in to Docker Hub | |
uses: docker/login-action@v3 | |
with: | |
username: ${{ secrets.DOCKERHUB_USERNAME }} | |
password: ${{ secrets.DOCKERHUB_TOKEN }} | |
- name: Extract Git tag | |
id: tag | |
run: | | |
TAG=${GITHUB_REF##*/} | |
echo "##[set-output name=VERSION;]$TAG" | |
- name: Build and Push Docker image | |
uses: docker/build-push-action@v5 | |
with: | |
context: . | |
push: true | |
tags: | | |
${{ secrets.DOCKERHUB_USERNAME }}/union-chatbot:${{ steps.tag.outputs.VERSION }} | |
${{ secrets.DOCKERHUB_USERNAME }}/union-chatbot:latest | |
- name: Deploy to server via SSH | |
uses: appleboy/ssh-action@v1.0.0 | |
with: | |
host: ${{ secrets.SERVER_HOST }} | |
username: ${{ secrets.SERVER_USERNAME }} | |
key: ${{ secrets.SERVER_SSH_KEY }} | |
script: | | |
set -e | |
cd ${{ secrets.PATH_TO_PROJECT_DIR }} | |
echo "Pulling latest git commit..." | |
git pull origin main | |
echo "Logging in to Docker Hub..." | |
echo "${{ secrets.DOCKERHUB_TOKEN }}" | docker login -u ${{ secrets.DOCKERHUB_USERNAME }} --password-stdin | |
echo "Pulling latest Docker images..." | |
docker-compose -f docker-compose-prod.yml pull | |
echo "Restarting containers..." | |
docker-compose -f docker-compose-prod.yml up -d | |
echo "Removing old images (optional cleanup):" | |
docker image prune -af | |