Skip to content

Commit

Permalink
ci: testing build
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmillennick committed Feb 4, 2025
1 parent 6e7e69f commit a7abd9d
Show file tree
Hide file tree
Showing 3 changed files with 112 additions and 108 deletions.
115 changes: 67 additions & 48 deletions .github/workflows/build-push-container.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,50 +22,6 @@ jobs:
matrix:
architecture: [x86_64, arm64]
runs-on: ${{ matrix.architecture == 'x86_64' && 'buildjet-8vcpu-ubuntu-2204' || 'buildjet-8vcpu-ubuntu-2204-arm' }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
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:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.INFRA_GH_TOKEN }}

- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_HUB_USERNAME }}
password: ${{ secrets.DOCKER_HUB_TOKEN }}

- name: Build and push container tags
run: |
./scripts/docker/build-push-container -n ${{ inputs.container_name }}
container-manifest:
name: Manifest ${{ inputs.container_name }}
needs: container-build
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
Expand All @@ -79,13 +35,76 @@ jobs:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.INFRA_GH_TOKEN }}

- name: Login to Docker Hub
- name: Login to Docker Hub for rate limiting
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_HUB_USERNAME }}
password: ${{ secrets.DOCKER_HUB_TOKEN }}

- name: Build and push container manifest
- name: Set up QEMU
uses: docker/setup-qemu-action@v3

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Build and push container tags
run: |
./scripts/docker/build-push-manifest -n ${{ inputs.container_name }}
./scripts/docker/build-push-container -n ${{ inputs.container_name }}
# - name: Build and push
# uses: docker/build-push-action@v6
# with:
# platforms: linux/amd64,linux/arm64
# push: true
# tags: user/app:latest
# - name: Checkout repository
# uses: actions/checkout@v4
# with:
# submodules: true
# ref: ${{ github.event.pull_request.head.ref || github.ref }}


# - name: Login to GHCR
# uses: docker/login-action@v3
# with:
# registry: ghcr.io
# username: ${{ github.repository_owner }}
# password: ${{ secrets.INFRA_GH_TOKEN }}

# - name: Login to Docker Hub for rate limiting
# uses: docker/login-action@v3
# with:
# username: ${{ secrets.DOCKER_HUB_USERNAME }}
# password: ${{ secrets.DOCKER_HUB_TOKEN }}

# - name: Build and push container tags
# run: |
# ./scripts/docker/build-push-container -n ${{ inputs.container_name }}

# container-manifest:
# name: Manifest ${{ inputs.container_name }}
# needs: container-build
# runs-on: ubuntu-latest
# steps:
# - name: Checkout repository
# uses: actions/checkout@v4
# with:
# submodules: true
# ref: ${{ github.event.pull_request.head.ref || github.ref }}

# - name: Login to GHCR
# uses: docker/login-action@v3
# with:
# registry: ghcr.io
# username: ${{ github.repository_owner }}
# password: ${{ secrets.INFRA_GH_TOKEN }}

# - name: Login to Docker Hub
# uses: docker/login-action@v3
# with:
# username: ${{ secrets.DOCKER_HUB_USERNAME }}
# password: ${{ secrets.DOCKER_HUB_TOKEN }}

# - name: Build and push container manifest
# run: |
# ./scripts/docker/build-push-manifest -n ${{ inputs.container_name }}
53 changes: 31 additions & 22 deletions scripts/docker/build-push-container
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ 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 git describe --exact-match --tags HEAD >/dev/null 2>&1; then
is_tag="true"
fi

if [ "$debug" = true ]; then
echo "COMMIT_HASH: $commit_hash"
Expand All @@ -66,10 +66,13 @@ arch=$(uname -m)
# Determine the platform name suffix based on the architecture
case "$arch" in
x86_64)
platform_suffix="-amd64"
platform_shorthand="amd64"
;;
aarch64)
platform_suffix="-arm64"
platform_shorthand="arm64"
;;
arm64)
platform_shorthand="arm64"
;;
*)
echo "Unsupported architecture: $arch"
Expand All @@ -79,7 +82,7 @@ esac

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

# Get application version
Expand All @@ -91,33 +94,39 @@ fi

# Generate image tags
container_tags=()
container_tag_commit="${repository}/${container_name}:${commit_hash}${platform_suffix}"
container_tag_version="${repository}/${container_name}:${application_version}${platform_suffix}"
container_tag_branch="${repository}/${container_name}:${application_version}-${sanitized_branch_name}${platform_suffix}"
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}"



container_tags+=("$container_tag_commit")
container_tags+=("$container_tag_branch")
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 build $git_root \
-f $dockerfile_path \
$(for tag in "${container_tags[@]}"; do echo -n " -t $tag"; done)
docker buildx build \
--platform "linux/amd64,linux/arm64" \
--file "$dockerfile_path" \
$(for tag in "${container_tags[@]}"; do echo -n " -t $tag "; done) \
--push \
"$git_root"

# Push the Docker images
for tag in "${container_tags[@]}"; do
docker push $tag
done
# # build and tag the docker image
# docker build $git_root \
# -f $dockerfile_path \
# $(for tag in "${container_tags[@]}"; do echo -n " -t $tag"; done)

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

52 changes: 14 additions & 38 deletions scripts/docker/build-push-manifest
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ 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 git describe --exact-match --tags HEAD >/dev/null 2>&1; then
is_tag="true"
fi

if [ "$debug" = true ]; then
echo "COMMIT_HASH: $commit_hash"
Expand All @@ -60,28 +60,6 @@ if [ "$debug" = true ]; then
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/')

Expand All @@ -95,30 +73,28 @@ 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}"



container_tags+=("$container_tag_commit")
container_tags+=("$container_tag_branch")
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
for tag in "${container_tags[@]}"; do
docker pull $tag-amd64
docker pull $tag-arm64
done

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

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

0 comments on commit a7abd9d

Please sign in to comment.