Skip to content

Build and Push Docker Images #5

Build and Push Docker Images

Build and Push Docker Images #5

name: Build and Push Docker Images
on:
workflow_dispatch:
inputs:
environment:
type: choice
description: "Select environment"
required: true
options:
- finney
- testnet
env:
REGISTRY: ghcr.io
ORGANIZATION: ${{ github.repository_owner }}
jobs:
build-and-push:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Log in to the Container registry
uses: docker/login-action@v2
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Build and push Docker images
run: |
for dir in ./scraper_service/shovel_*/; do
if [ -f "${dir}Dockerfile" ]; then
dir_name=$(basename "$dir")
echo "Building and pushing image for $dir_name"
docker buildx build \
-f ${dir}/Dockerfile \
--push \
--tag ${{ env.REGISTRY }}/${{ env.ORGANIZATION }}/${dir_name}:${{ github.sha }} \
./scraper_service
fi
done
- name: Update YAML in other repository
env:
PAT: ${{ secrets.PAT_FOR_PRIVATE_REPO }}
run: |
git clone https://${PAT}@github.com/opentensor/ops-setup.git
for dir in ./scraper_service/shovel_*/; do
if [ -f "${dir}Dockerfile" ]; then
dir_name=$(basename "$dir")
if [ "${{ github.event.inputs.environment }}" == "finney" ]; then
yaml_file="ops-setup/clusters/data-warehouse-finney/indexers/${dir}.yaml"
elif [ "${{ github.event.inputs.environment }}" == "testnet" ]; then
yaml_file="ops-setup/clusters/data-warehouse-testnet/indexers/${dir}.yaml"
fi
if [ -f "$yaml_file" ]; then
sed -i 's|image: .*|image: ${{ env.REGISTRY }}/${{ env.ORGANIZATION }}/'${dir}':${{ github.sha }}|' "$yaml_file"
else
echo "Warning: $yaml_file not found"
fi
fi
done
cd ops-setup
git config user.name github-actions
git config user.email github-actions@github.com
git add .
git commit -m "Update indexers on ${{github.events.inputs.environment}} tags to ${{ github.sha }}"
git push