Skip to content

Build and Push Docker Image Validator Script #8

Build and Push Docker Image Validator Script

Build and Push Docker Image Validator Script #8

name: Build and Push Docker Image Validator Script
on:
workflow_dispatch: {}
jobs:
build-and-push:
runs-on: ubuntu-latest
steps:
# Check authorized user
- name: Check Triggering User
run: |
AUTHORIZED_USERS=("pravin-X109" "ManavShahWasTaken" "donaldknoller")
if [[ ! " ${AUTHORIZED_USERS[@]} " =~ " ${{ github.actor }} " ]]; then
echo "::error::Unauthorized user: ${{ github.actor }}"
exit 1
fi
# Checkout the repository
- name: Checkout code
uses: actions/checkout@v3
# Log in to GitHub Container Registry
- name: Log in to GitHub Container Registry
env:
GHCR_USERNAME: ${{ secrets.GHCR_USERNAME }}
GHCR_TOKEN: ${{ secrets.GHCR_TOKEN }}
run: |
if [ -z "$GHCR_USERNAME" ] || [ -z "$GHCR_TOKEN" ]; then
echo "::error::GHCR_USERNAME or GHCR_TOKEN secret is missing"
exit 1
fi
echo "$GHCR_TOKEN" | docker login ghcr.io -u "$GHCR_USERNAME" --password-stdin
# Set dynamic image tag
- name: Set Image Tag
run: echo "IMAGE_TAG=ghcr.io/${{ secrets.GHCR_USERNAME }}/validator_script_image:${{ github.sha }}" >> $GITHUB_ENV
# Build the Docker image
- name: Build Docker Image
run: |
docker build -f validator_updater/Dockerfile.validator \
-t $IMAGE_TAG .
# Push the Docker image to GHCR
- name: Push Docker Image
run: |
for i in {1..3}; do
docker push $IMAGE_TAG && break || sleep 10
done