Merge pull request #55 from techknowledge-blog/hotfix/description-column #55
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: Docker Image CI | |
| #sed command - replacing the value of .env file - variable IMAGE_TAG for the latest one | |
| on: | |
| push: | |
| branches: [ "main" ] | |
| pull_request: | |
| branches: [ "main" ] | |
| jobs: | |
| build: | |
| runs-on: ubuntu-latest | |
| outputs: | |
| timestamp: ${{ steps.timestamp.outputs.timestamp }} | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Get timestamp | |
| id: timestamp | |
| run: echo "timestamp=$(date +%s%3N)" >> $GITHUB_OUTPUT && echo "::set-output name=timestamp::$(date +%s%3N)" | |
| - name: Build the Docker image | |
| run: docker build . --file Dockerfile --tag techknowledge-api-nest-container:${{ steps.timestamp.outputs.timestamp }} | |
| - name: Login to Docker Hub | |
| run: echo ${{ secrets.DOCKER_HUB_PASSWORD }} | docker login -u ${{ secrets.DOCKER_HUB_USERNAME }} --password-stdin | |
| - name: Tag the image | |
| run: docker tag techknowledge-api-nest-container:${{ steps.timestamp.outputs.timestamp }} ${{ secrets.DOCKER_HUB_USERNAME }}/techknowledge-api-nest-container:${{ steps.timestamp.outputs.timestamp }} | |
| - name: Push the image | |
| run: docker push ${{ secrets.DOCKER_HUB_USERNAME }}/techknowledge-api-nest-container:${{ steps.timestamp.outputs.timestamp }} | |
| deploy: | |
| needs: build | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: SSH into server and update | |
| uses: appleboy/ssh-action@v0.1.7 | |
| with: | |
| host: ${{ secrets.PROD_SERVER_IP }} | |
| username: ${{ secrets.SERVER_USERNAME }} | |
| key: ${{ secrets.SERVER_PRIVATE_KEY }} | |
| script: | | |
| cd ~/projects/blog-techknowledge | |
| docker login -u ${{ secrets.DOCKER_HUB_USERNAME }} -p ${{ secrets.DOCKER_HUB_PASSWORD }} | |
| docker pull mikkaiserdev/techknowledge-api-nest-container:${{ needs.build.outputs.timestamp }} | |
| sed -i 's/^IMAGE_TAG=.*/IMAGE_TAG=${{ needs.build.outputs.timestamp }}/' .env | |
| docker compose down | |
| docker rm -f postgres-container | |
| docker rm -f techknowledge-api-nest-container | |
| docker compose up -d --force-recreate |