Skip to content

Fix git action

Fix git action #5

Workflow file for this run

name: Build and Push Docker Image
# Trigger the workflow on push or pull request to the main branch
on:
push:
tags:
- 'v*'
branches:
- master
pull_request:
branches:
- master
jobs:
# Get version tag
get_tag:
runs-on: ubuntu-latest
steps:
- name: Determine deployment tag
id: deployment_tag
run: |
if [[ '${{ github.ref_type }}' == 'tag' ]]; then
export tag=${{ github.ref_name }}
echo "version tag is $tag"
echo "id=$tag" >> $GITHUB_OUTPUT
else
export tag=${{ github.sha }}
echo "version tag is $tag"
echo "id=$tag" >> $GITHUB_OUTPUT
fi
outputs:
deployment_tag: ${{ steps.deployment_tag.outputs.id }}
build-and-push:
needs: [ get_tag ]
runs-on: ubuntu-latest
steps:
# Step 1: Check out the repository code
- name: Checkout code
uses: actions/checkout@v4
# Step 2: Set up Docker Buildx (for multi-platform builds, optional)
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
# Step 3: Log in to Docker Hub using secrets
- name: Log in to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
# Step 4: Build and push the Docker image
- name: Build and push frontend Docker image
uses: docker/build-push-action@v5
with:
context: ./front # Build context (root directory, adjust if Dockerfile is elsewhere)
file: ./front/Dockerfile # Path to Dockerfile
push: ${{ github.event_name != 'pull_request' }} # Only push on push events, not PRs
tags: |
docker.io/bsvb/truth-machine-demo:${{ github.sha }}
docker.io/bsvb/truth-machine: ${{ needs.get_tag.outputs.deployment_tag }}
# Step 5: Build and push the backend Docker image
- name: Build and push frontend Docker image
uses: docker/build-push-action@v5
with:
context: ./back # Build context (root directory, adjust if Dockerfile is elsewhere)
file: ./back/Dockerfile # Path to Dockerfile
push: ${{ github.event_name != 'pull_request' }} # Only push on push events, not PRs
tags: |
docker.io/bsvb/truth-machine:${{ github.sha }}
docker.io/bsvb/truth-machine:latest