Skip to content

Commit

Permalink
Refactor Docker image build and push logic in create_packages.yml
Browse files Browse the repository at this point in the history
- Simplified the build process to only build changed images and their dependents, removing unnecessary checks for tags and production branches.
- Updated the push logic to only push images that were built, enhancing efficiency and clarity in the workflow.

These changes streamline the CI/CD process for Docker images, ensuring that only relevant images are built and pushed based on changes detected.
  • Loading branch information
jhagberg committed Jan 2, 2025
1 parent 4b21e1e commit 2eefb99
Showing 1 changed file with 14 additions and 26 deletions.
40 changes: 14 additions & 26 deletions .github/workflows/create_packages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -87,20 +87,15 @@ jobs:
DOCKER_BUILDKIT: 1
COMPOSE_DOCKER_CLI_BUILD: 1
run: |
# Always build all images for tags and production branches
if [[ "${{ github.ref_type }}" == "tag" || "${{ github.ref_name }}" == "production" ]]; then
docker compose build --build-arg BUILDKIT_INLINE_CACHE=1
else
# Only build changed images and their dependents for other branches
if [[ "${{ needs.changes.outputs.frontend }}" == "true" ]]; then
docker compose build --build-arg BUILDKIT_INLINE_CACHE=1 herdbook-frontend main
elif [[ "${{ needs.changes.outputs.main }}" == "true" ]]; then
docker compose build --build-arg BUILDKIT_INLINE_CACHE=1 main
fi
# Only build changed images and their dependents
if [[ "${{ needs.changes.outputs.frontend }}" == "true" ]]; then
docker compose build --build-arg BUILDKIT_INLINE_CACHE=1 herdbook-frontend main
elif [[ "${{ needs.changes.outputs.main }}" == "true" ]]; then
docker compose build --build-arg BUILDKIT_INLINE_CACHE=1 main
fi
if [[ "${{ needs.changes.outputs.r-api }}" == "true" ]]; then
docker compose build --build-arg BUILDKIT_INLINE_CACHE=1 r-api
fi
if [[ "${{ needs.changes.outputs.r-api }}" == "true" ]]; then
docker compose build --build-arg BUILDKIT_INLINE_CACHE=1 r-api
fi
# Push images
Expand All @@ -124,20 +119,13 @@ jobs:
fi
}
# For tags and production/test-prod branches, push all images
if [[ "${{ github.ref_type }}" == "tag" || "${{ github.ref_name }}" == "production" || "${{ github.ref_name }}" == "test-prod" ]]; then
# Push only the images that were built
if [[ "${{ needs.changes.outputs.frontend }}" == "true" ]]; then
push_if_built "herdbook_frontend"
fi
if [[ "${{ needs.changes.outputs.main }}" == "true" || "${{ needs.changes.outputs.frontend }}" == "true" ]]; then
push_if_built "herdbook_main"
fi
if [[ "${{ needs.changes.outputs.r-api }}" == "true" ]]; then
push_if_built "herdbook_r-api"
else
# For other branches, push only the images that were built
if [[ "${{ needs.changes.outputs.frontend }}" == "true" ]]; then
push_if_built "herdbook_frontend"
fi
if [[ "${{ needs.changes.outputs.main }}" == "true" || "${{ needs.changes.outputs.frontend }}" == "true" ]]; then
push_if_built "herdbook_main"
fi
if [[ "${{ needs.changes.outputs.r-api }}" == "true" ]]; then
push_if_built "herdbook_r-api"
fi
fi

0 comments on commit 2eefb99

Please sign in to comment.