feat: update README #6
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: DevOps CI/CD Pipeline | |
| on: | |
| push: | |
| branches: ["main"] | |
| jobs: | |
| build: | |
| runs-on: ubuntu-latest | |
| steps: | |
| # Checkout the repository | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| # Log in to Docker Hub | |
| - name: Log in to Docker Hub | |
| uses: docker/login-action@v3 | |
| with: | |
| username: ${{ secrets.DOCKERHUB_USERNAME }} | |
| password: ${{ secrets.DOCKERHUB_TOKEN }} | |
| # Build and tag the Docker image | |
| - name: Build Docker image with Git SHA and Date tags | |
| run: | | |
| GIT_SHA=$(git rev-parse --short HEAD) | |
| DATE_TAG=$(date +'%Y-%m-%d') | |
| IMAGE_NAME=${{ secrets.DOCKERHUB_USERNAME }}/tempochat | |
| echo "GIT_SHA=${GIT_SHA}" | |
| echo "GIT_SHA=$GIT_SHA" >> $GITHUB_ENV | |
| echo "DATE_TAG=$DATE_TAG" >> $GITHUB_ENV | |
| echo "IMAGE_NAME=$IMAGE_NAME" >> $GITHUB_ENV | |
| echo "Building image: $IMAGE_NAME" | |
| docker build \ | |
| --build-arg GIT_SHA=${GIT_SHA} \ | |
| -t $IMAGE_NAME:latest \ | |
| -t $IMAGE_NAME:${DATE_TAG}_${GIT_SHA} . | |
| # Push all tags to Docker Hub | |
| - name: Push image to Docker Hub | |
| run: | | |
| IMAGE_NAME=${{ secrets.DOCKERHUB_USERNAME }}/tempochat | |
| docker push $IMAGE_NAME:latest | |
| docker push $IMAGE_NAME:${DATE_TAG}_${GIT_SHA} | |
| deploy: | |
| runs-on: ubuntu-latest | |
| needs: build | |
| steps: | |
| - name: Deploy via SSH | |
| uses: appleboy/ssh-action@v1.2.2 | |
| with: | |
| host: ${{ secrets.VPS_HOST }} | |
| username: ${{ secrets.VPS_USER }} | |
| password: ${{ secrets.VPS_PASSWORD }} | |
| script: | | |
| IMAGE=${{ secrets.DOCKERHUB_USERNAME }}/tempochat:latest | |
| cd ${{ secrets.DEPLOY_PATH }} | |
| echo "${{ secrets.ENV_FILE }}" | tr -d '\r' > .env | |
| docker compose -f docker-compose.${{ secrets.SERVICE_NAME }}.yml pull | |
| docker compose -f docker-compose.${{ secrets.SERVICE_NAME }}.yml up -d | |
| docker system prune -f | |
| rm .env |