Skip to content

Fix/default dev fix db volumes #14

Fix/default dev fix db volumes

Fix/default dev fix db volumes #14

name: Build and Push Docker Image
on:
workflow_dispatch:
inputs:
shardeum_branch:
description: 'Shardeum repository branch'
required: true
default: 'dev'
relayer_collector_branch:
description: 'Relayer collector repository branch'
required: true
default: 'dev'
json_rpc_server_branch:
description: 'JSON RPC server repository branch'
required: true
default: 'dev'
image_tag:
description: 'Docker image tag'
required: true
default: 'dev'
push_latest:
description: 'Push latest tag'
type: boolean
required: true
default: false
pull_request:
branches: [ main ]
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
jobs:
build-and-push:
runs-on: ubuntu-latest
timeout-minutes: 120
permissions:
contents: read
packages: write
pull-requests: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Log in to the Container registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Determine architecture
id: arch
run: |
ARCH=$(uname -m)
if [ "$ARCH" == "aarch64" ] || [ "$ARCH" == "arm64" ]; then
echo "ARCH_TAG=arm64" >> $GITHUB_OUTPUT
elif [ "$ARCH" == "x86_64" ]; then
echo "ARCH_TAG=amd64" >> $GITHUB_OUTPUT
else
echo "Unsupported architecture: $ARCH. Exiting."
exit 1
fi
- name: Set build args and tags
id: build_config
run: |
if [ "${{ github.event_name }}" == "pull_request" ]; then
echo "SHARDEUM_BRANCH=dev" >> $GITHUB_OUTPUT
echo "RELAYER_COLLECTOR_BRANCH=dev" >> $GITHUB_OUTPUT
echo "JSON_RPC_SERVER_BRANCH=dev" >> $GITHUB_OUTPUT
echo "IMAGE_TAG=pr-preview-${{ github.event.pull_request.number }}" >> $GITHUB_OUTPUT
else
echo "SHARDEUM_BRANCH=${{ inputs.shardeum_branch }}" >> $GITHUB_OUTPUT
echo "RELAYER_COLLECTOR_BRANCH=${{ inputs.relayer_collector_branch }}" >> $GITHUB_OUTPUT
echo "JSON_RPC_SERVER_BRANCH=${{ inputs.json_rpc_server_branch }}" >> $GITHUB_OUTPUT
echo "IMAGE_TAG=${{ inputs.image_tag }}" >> $GITHUB_OUTPUT
fi
- name: Build Docker image
run: |
TAGS="-t ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}-${{ steps.arch.outputs.ARCH_TAG }}:${{ steps.build_config.outputs.IMAGE_TAG }}"
if [ "${{ github.event_name }}" == "workflow_dispatch" ] && [ "${{ inputs.push_latest }}" == "true" ]; then
TAGS="$TAGS -t ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}-${{ steps.arch.outputs.ARCH_TAG }}:latest"
fi
docker build \
--build-arg SHARDEUM_BRANCH=${{ steps.build_config.outputs.SHARDEUM_BRANCH }} \
--build-arg RELAYER_COLLECTOR_BRANCH=${{ steps.build_config.outputs.RELAYER_COLLECTOR_BRANCH }} \
--build-arg JSON_RPC_SERVER_BRANCH=${{ steps.build_config.outputs.JSON_RPC_SERVER_BRANCH }} \
$TAGS \
.
- name: Push Docker image
run: |
docker push ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}-${{ steps.arch.outputs.ARCH_TAG }}:${{ steps.build_config.outputs.IMAGE_TAG }}
if [ "${{ github.event_name }}" == "workflow_dispatch" ] && [ "${{ inputs.push_latest }}" == "true" ]; then
docker push ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}-${{ steps.arch.outputs.ARCH_TAG }}:latest
fi
- name: Comment PR with Docker instructions
if: github.event_name == 'pull_request'
uses: actions/github-script@v6
with:
script: |
const imageTag = 'pr-preview-${{ github.event.pull_request.number }}';
const comment = `
### 🐳 Docker Image Preview Available
You can test this PR using the following Docker image:
\`\`\`bash
docker pull ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}-${{ steps.arch.outputs.ARCH_TAG }}:${imageTag}
docker run -it ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}-${{ steps.arch.outputs.ARCH_TAG }}:${imageTag}
\`\`\`
> Note: This image was built for ${{ steps.arch.outputs.ARCH_TAG }} architecture
`;
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: comment
});