Skip to content

Commit

Permalink
ci: fixed container manifest workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmillennick committed Jan 21, 2025
1 parent fc7228c commit 5b02eb2
Show file tree
Hide file tree
Showing 2 changed files with 142 additions and 2 deletions.
20 changes: 18 additions & 2 deletions .github/workflows/build-push-container.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,23 @@ jobs:
with:
submodules: true
ref: ${{ github.event.pull_request.head.ref || github.ref }}


- name: Cache Cargo registry
uses: actions/cache@v3
with:
path: ~/.cargo/registry
key: ${{ runner.os }}-cargo-registry-${{ hashFiles('**/Cargo.lock') }}
restore-keys: |
${{ runner.os }}-cargo-registry-
- name: Cache Cargo index
uses: actions/cache@v3
with:
path: ~/.cargo/git
key: ${{ runner.os }}-cargo-index-${{ hashFiles('**/Cargo.lock') }}
restore-keys: |
${{ runner.os }}-cargo-index-
- name: Login to GHCR
uses: docker/login-action@v3
with:
Expand Down Expand Up @@ -72,4 +88,4 @@ jobs:

- name: Build and push container manifest
run: |
./scripts/movement/manifest ${{ inputs.container_name }}
./scripts/docker/build-push-manifest ${{ inputs.container_name }}
124 changes: 124 additions & 0 deletions scripts/docker/build-push-manifest
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
#!/bin/bash
set -e

# Turn on bash safety options: fail on error, variable unset and error in piped process
set -eou pipefail

# Initialize parameters
debug=false
container_name=movement-full-node
repository=ghcr.io/movementlabsxyz

# Example: add "d" as a boolean toggle
while getopts "dn:r:" opt; do
case "$opt" in
d)
debug=true
;;
n)
container_name=$OPTARG
;;
r)
repository=$OPTARG
;;
*)
echo "Usage: $0 [-d] -n <container-name> -r <repository>"
exit 1
;;
esac
done

if [ "$debug" = true ]; then
echo "Debug mode is on"
echo "CONTAINER_NAME: $container_name"
echo "REPOSITORY: $repository"
fi

# Get dockerfile path
git_root=$(git rev-parse --show-toplevel)
dockerfile_path=${git_root}/docker/build/${container_name}/Dockerfile

if [ "$debug" = true ]; then
echo "GIT_ROOT: $git_root"
echo "DOCKERFILE: $dockerfile_path"
fi

# Get git info
commit_hash=$(git rev-parse HEAD | cut -c1-7)
branch_name=$(git rev-parse --abbrev-ref HEAD)
sanitized_branch_name=${branch_name//\//.}
is_tag=false

# if git describe --exact-match --tags HEAD >/dev/null 2>&1; then
# is_tag="true"
# fi

if [ "$debug" = true ]; then
echo "COMMIT_HASH: $commit_hash"
echo "BRANCH_NAME: $branch_name"
echo "SANITIZED_BRANCH_NAME: $sanitized_branch_name"
echo "IS_TAG: $is_tag"
fi

# Get the machine hardware name
arch=$(uname -m)

# Determine the platform name suffix based on the architecture
case "$arch" in
x86_64)
platform_suffix="-amd64"
;;
aarch64)
platform_suffix="-arm64"
;;
*)
echo "Unsupported architecture: $arch"
exit 1
;;
esac

if [ "$debug" = true ]; then
echo "ARCH: $arch"
echo "PLATFORM_SUFFIX: $platform_suffix"
fi

# Get application version
application_version=$(grep -m1 '^version\s*=' Cargo.toml | sed 's/^version\s*=\s*"\(.*\)"/\1/')

if [ "$debug" = true ]; then
echo "APPLICATION_VERSION: $application_version"
fi

# Generate image tags
container_tags=()
container_tag_commit="${repository}/${container_name}:${commit_hash}"
container_tag_version="${repository}/${container_name}:${application_version}"
container_tag_branch="${repository}/${container_name}:${application_version}-${sanitized_branch_name}"

if [ "$is_tag" = true ]; then
# If it's a tag, use the application version
container_tags+=("$container_tag_version")
else
# If it's not a tag, use the sanitized branch name
container_tags+=("$container_tag_branch")
fi

container_tags+=("$container_tag_commit")

if [ "$debug" = true ]; then
for tag in "${container_tags[@]}"; do
echo "CONTAINER_TAG: $tag"
done
fi

# # build and tag the docker image
docker buildx imagetools create \
$container_tag_commit-amd64 \
$container_tag_commit-arm64 \
$(for tag in "${container_tags[@]}"; do echo -n " --tag $tag"; done)

# Push the Docker images
for tag in "${container_tags[@]}"; do
docker push $tag
done

0 comments on commit 5b02eb2

Please sign in to comment.