Change container name from 'app' to 'fops' #13
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 and Deploy | |
| on: | |
| push: | |
| branches: | |
| - master | |
| env: | |
| REGISTRY: ghcr.io | |
| jobs: | |
| build-and-deploy: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: read | |
| packages: write | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Normalize image name (lowercase) | |
| run: | | |
| echo "IMAGE_NAME=${GITHUB_REPOSITORY,,}" >> $GITHUB_ENV | |
| - name: Login to GitHub Container Registry (CI) | |
| run: | | |
| echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io \ | |
| -u "${{ github.actor }}" \ | |
| --password-stdin | |
| - name: Build Docker image | |
| run: | | |
| docker build \ | |
| -f backend/Dockerfile \ | |
| -t $REGISTRY/$IMAGE_NAME:latest \ | |
| -t $REGISTRY/$IMAGE_NAME:${{ github.sha }} \ | |
| backend | |
| - name: Push Docker image | |
| run: | | |
| docker push $REGISTRY/$IMAGE_NAME:latest | |
| docker push $REGISTRY/$IMAGE_NAME:${{ github.sha }} | |
| # ---------- DEPLOY ---------- | |
| - name: Setup SSH | |
| run: | | |
| set -x | |
| mkdir -p ~/.ssh | |
| echo "${{ secrets.DO_SSH_KEY }}" > ~/.ssh/id_ed25519 | |
| chmod 600 ~/.ssh/id_ed25519 | |
| echo "Scanning SSH host key..." | |
| ssh-keyscan -T 5 -H ${{ secrets.DO_HOST }} >> ~/.ssh/known_hosts || \ | |
| echo "ssh-keyscan failed, continuing anyway" | |
| - name: Deploy | |
| run: | | |
| # Construct the full image URL using the workflow env vars | |
| # This ensures you are pulling exactly what you just built | |
| IMAGE="$REGISTRY/$IMAGE_NAME:latest" | |
| CONTAINER="fops" | |
| echo "Deploying $IMAGE to remote server..." | |
| # The variables $IMAGE and $CONTAINER are expanded locally | |
| # before being sent to the remote server because we didn't quote 'EOF' | |
| ssh ${{ secrets.DO_USER }}@${{ secrets.DO_HOST }} << EOF | |
| set -e | |
| # Optional: If the package is Private, you must docker login here first | |
| # echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin | |
| docker pull $IMAGE | |
| docker rm -f $CONTAINER || true | |
| docker run -d --name $CONTAINER $IMAGE | |
| EOF |