Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[gha/docker] build with branch name; also cleanup #538

Merged
merged 2 commits into from
Oct 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions .github/workflows/build-images.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,6 @@ on:
push:
branches:
- main
# aptos-indexer-processors network-specific release branches
- aptos-indexer-processors-devnet
- aptos-indexer-processors-testnet
- aptos-indexer-processors-mainnet

# cancel redundant builds
concurrency:
Expand Down Expand Up @@ -37,4 +33,12 @@ jobs:
with:
GCP_SERVICE_ACCOUNT_EMAIL: ${{ secrets.GCP_SERVICE_ACCOUNT_EMAIL }}
GCP_WORKLOAD_IDENTITY_PROVIDER: ${{ secrets.GCP_WORKLOAD_IDENTITY_PROVIDER }}
- run: ./scripts/build-and-push-images.sh ${{ matrix.example }}
- name: Extract branch name
shell: bash
run: echo "branch=${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}" >> $GITHUB_OUTPUT
id: extract_branch
- name: Build and push images
run: ./scripts/build-and-push-images.sh ${{ matrix.example }}
env:
GIT_BRANCH: ${{ steps.extract_branch.outputs.branch }}

Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
name: Copy images to dockerhub on release
on:
push:
branches:
# aptos-indexer-processors network-specific release branches
- aptos-indexer-processors-devnet
- aptos-indexer-processors-testnet
- aptos-indexer-processors-mainnet
tags:
- aptos-indexer-processors-v*

Expand Down
17 changes: 16 additions & 1 deletion scripts/build-and-push-images.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,29 @@ else
CREDENTIAL_MOUNT="$HOME/.config/gcloud:/root/.config/gcloud:ro"
fi

# Normalize GIT_BRANCH if it's set
if [ -n "${GIT_BRANCH}" ]; then
export NORMALIZED_GIT_BRANCH=$(printf "${GIT_BRANCH}" | sed -e 's/[^a-zA-Z0-9]/-/g')
fi

for example in $EXAMPLES_TO_BUILD; do
# Set DESTINATIONS based on GIT_SHA since that is always set
DESTINATIONS="--destination ${TARGET_REGISTRY}/${example}:${GIT_SHA}"

# If GIT_BRANCH is set and not empty, add it as an additional tag
if [ -n "${NORMALIZED_GIT_BRANCH}" ]; then
DESTINATIONS="${DESTINATIONS} --destination ${TARGET_REGISTRY}/${example}:${NORMALIZED_GIT_BRANCH}"
DESTINATIONS="${DESTINATIONS} --destination ${TARGET_REGISTRY}/${example}:${NORMALIZED_GIT_BRANCH}_${GIT_SHA}"
fi

# build and push the image
docker run \
--rm \
-v $CREDENTIAL_MOUNT \
-v $(pwd)/$example:/workspace \
gcr.io/kaniko-project/executor:latest \
--dockerfile /workspace/Dockerfile \
--destination "$TARGET_REGISTRY/$example:$GIT_SHA" \
$DESTINATIONS \
--context dir:///workspace/ \
--cache=true
done
Loading