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
- Updated the build process to differentiate between tag/production branches and other branches, ensuring that the frontend and main images are built and pushed accordingly.
- Simplified the conditions for building and pushing images based on changes detected, enhancing the efficiency of the CI/CD workflow.

These changes streamline the Docker image management process, ensuring only relevant images are built and pushed based on the current branch context.
  • Loading branch information
jhagberg committed Jan 2, 2025
1 parent 2eefb99 commit 6c47a02
Showing 1 changed file with 25 additions and 14 deletions.
39 changes: 25 additions & 14 deletions .github/workflows/create_packages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -87,15 +87,20 @@ jobs:
DOCKER_BUILDKIT: 1
COMPOSE_DOCKER_CLI_BUILD: 1
run: |
# Only build changed images and their dependents
if [[ "${{ needs.changes.outputs.frontend }}" == "true" ]]; then
# For tags and production branch, build frontend and main
if [[ "${{ github.ref_type }}" == "tag" || "${{ github.ref_name }}" == "production" ]]; 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
else
# For other branches, 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
if [[ "${{ needs.changes.outputs.r-api }}" == "true" ]]; then
docker compose build --build-arg BUILDKIT_INLINE_CACHE=1 r-api
fi
fi
# Push images
Expand All @@ -119,13 +124,19 @@ jobs:
fi
}
# Push only the images that were built
if [[ "${{ needs.changes.outputs.frontend }}" == "true" ]]; then
# For tags and production branch, push frontend and main
if [[ "${{ github.ref_type }}" == "tag" || "${{ github.ref_name }}" == "production" ]]; 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 6c47a02

Please sign in to comment.