From d6ffd193d31a9b38cac0378fb3a3f30e53da5bb4 Mon Sep 17 00:00:00 2001 From: Julien Neuhart Date: Thu, 14 Aug 2025 20:40:38 +0200 Subject: [PATCH] ci(build): #540 add AWS Lambda support --- .env | 1 + .github/actions/build-test-push/action.yml | 4 ++ .github/actions/build-test-push/build.sh | 51 ++++++++++++++------ .github/actions/clean/clean.sh | 1 + .github/workflows/continuous-delivery.yml | 10 +++- .github/workflows/continuous-integration.yml | 19 +++++++- 6 files changed, 69 insertions(+), 17 deletions(-) diff --git a/.env b/.env index 7179b1f0..993c849f 100644 --- a/.env +++ b/.env @@ -3,4 +3,5 @@ DOCKER_REGISTRY=gotenberg DOCKER_REPOSITORY=gotenberg DOCKERFILE=build/Dockerfile DOCKERFILE_CLOUDRUN=build/Dockerfile.cloudrun +DOCKERFILE_AWS_LAMBDA=build/Dockerfile.aws-lambda DOCKER_BUILD_CONTEXT='.' diff --git a/.github/actions/build-test-push/action.yml b/.github/actions/build-test-push/action.yml index 767bb76b..66bc9dfd 100644 --- a/.github/actions/build-test-push/action.yml +++ b/.github/actions/build-test-push/action.yml @@ -34,6 +34,9 @@ outputs: tags_cloud_run: description: Comma separated list of Cloud Run tags (linux/amd64 only) value: ${{ steps.build.outputs.tags_cloud_run }} + tags_aws_lambda: + description: Comma separated list of AWS Lambda tags (linux/amd64 and linux/arm64 only) + value: ${{ steps.build.outputs.tags_aws_lambda }} runs: using: composite @@ -87,3 +90,4 @@ runs: run: | echo "tags=${{ steps.build.outputs.tags }}" echo "tags_cloud_run=${{ steps.build.outputs.tags_cloud_run }}" + echo "tags_aws_lambda=${{ steps.build.outputs.tags_aws_lambda }}" diff --git a/.github/actions/build-test-push/build.sh b/.github/actions/build-test-push/build.sh index 170ba574..dd5da2c4 100755 --- a/.github/actions/build-test-push/build.sh +++ b/.github/actions/build-test-push/build.sh @@ -56,6 +56,7 @@ fi # Build tags arrays. tags=() tags_cloud_run=() +tags_aws_lambda=() IFS='/' read -ra arch <<< "$platform" IFS='.' read -ra semver <<< "$version" @@ -79,6 +80,13 @@ if [ "${#semver[@]}" -eq 3 ]; then tags_cloud_run+=("$DOCKER_REGISTRY/$DOCKER_REPOSITORY:$major.$minor-cloudrun") tags_cloud_run+=("$DOCKER_REGISTRY/$DOCKER_REPOSITORY:$major.$minor.$patch-cloudrun") fi + + if [ "$platform" = "linux/amd64" ] || [ "$platform" = "linux/arm64" ]; then + tags_aws_lambda+=("$DOCKER_REGISTRY/$DOCKER_REPOSITORY:latest-aws-lambda-${arch[1]}") + tags_aws_lambda+=("$DOCKER_REGISTRY/$DOCKER_REPOSITORY:$major-aws-lambda-${arch[1]}") + tags_aws_lambda+=("$DOCKER_REGISTRY/$DOCKER_REPOSITORY:$major.$minor-aws-lambda-${arch[1]}") + tags_aws_lambda+=("$DOCKER_REGISTRY/$DOCKER_REPOSITORY:$major.$minor.$patch-aws-lambda-${arch[1]}") + fi else echo echo "Non-semver version detected, fallback to $version" @@ -87,10 +95,15 @@ else if [ "$platform" = "linux/amd64" ]; then tags_cloud_run+=("$DOCKER_REGISTRY/$DOCKER_REPOSITORY:$version-cloudrun") fi + + if [ "$platform" = "linux/amd64" ] || [ "$platform" = "linux/arm64" ]; then + tags_aws_lambda+=("$DOCKER_REGISTRY/$DOCKER_REPOSITORY:$version-aws-lambda-${arch[1]}") + fi fi tags_flags=() tags_cloud_run_flags=() +tags_aws_lambda_flags=() echo "Will use the following tags:" for tag in "${tags[@]}"; do @@ -101,6 +114,10 @@ for tag in "${tags_cloud_run[@]}"; do tags_cloud_run_flags+=("-t" "$tag") echo "- $tag" done +for tag in "${tags_aws_lambda[@]}"; do + tags_aws_lambda_flags+=("-t" "$tag") + echo "- $tag" +done echo # Build images. @@ -138,24 +155,30 @@ cmd="docker buildx build \ " run_cmd "$cmd" -if [ "$platform" != "linux/amd64" ]; then - echo "⚠️ Skip Cloud Run variant(s)" - echo "✅ Done!" - echo "tags=$(join "," "${tags[@]}")" >> "$GITHUB_OUTPUT" - echo "tags_cloud_run=$(join "," "${tags_cloud_run[@]}")" >> "$GITHUB_OUTPUT" - exit 0 +if [ "$platform" = "linux/amd64" ]; then + cmd="docker build \ + --build-arg DOCKER_REGISTRY=$DOCKER_REGISTRY \ + --build-arg DOCKER_REPOSITORY=$DOCKER_REPOSITORY \ + --build-arg GOTENBERG_VERSION=$version \ + ${tags_cloud_run_flags[*]} \ + -f $DOCKERFILE_CLOUDRUN $DOCKER_BUILD_CONTEXT + " + run_cmd "$cmd" fi -cmd="docker build \ - --build-arg DOCKER_REGISTRY=$DOCKER_REGISTRY \ - --build-arg DOCKER_REPOSITORY=$DOCKER_REPOSITORY \ - --build-arg GOTENBERG_VERSION=$version \ - ${tags_cloud_run_flags[*]} \ - -f $DOCKERFILE_CLOUDRUN $DOCKER_BUILD_CONTEXT -" -run_cmd "$cmd" +if [ "$platform" = "linux/amd64" ] || [ "$platform" = "linux/arm64" ]; then + cmd="docker build \ + --build-arg DOCKER_REGISTRY=$DOCKER_REGISTRY \ + --build-arg DOCKER_REPOSITORY=$DOCKER_REPOSITORY \ + --build-arg GOTENBERG_VERSION=$version \ + ${tags_aws_lambda_flags[*]} \ + -f $DOCKERFILE_AWS_LAMBDA $DOCKER_BUILD_CONTEXT + " + run_cmd "$cmd" +fi echo "✅ Done!" echo "tags=$(join "," "${tags[@]}")" >> "$GITHUB_OUTPUT" echo "tags_cloud_run=$(join "," "${tags_cloud_run[@]}")" >> "$GITHUB_OUTPUT" +echo "tags_aws_lambda=$(join "," "${tags_aws_lambda[@]}")" >> "$GITHUB_OUTPUT" exit 0 diff --git a/.github/actions/clean/clean.sh b/.github/actions/clean/clean.sh index b89a9536..14a5429e 100755 --- a/.github/actions/clean/clean.sh +++ b/.github/actions/clean/clean.sh @@ -40,6 +40,7 @@ IFS=',' read -ra tags_to_delete <<< "$tags" if [ -n "$snapshot_version" ]; then tags_to_delete+=("$DOCKER_REGISTRY/snapshot:$snapshot_version") tags_to_delete+=("$DOCKER_REGISTRY/snapshot:$snapshot_version-cloudrun") + tags_to_delete+=("$DOCKER_REGISTRY/snapshot:$snapshot_version-aws-lambda") fi echo "Will delete the following tag(s):" diff --git a/.github/workflows/continuous-delivery.yml b/.github/workflows/continuous-delivery.yml index 1bb094e6..cae571f5 100644 --- a/.github/workflows/continuous-delivery.yml +++ b/.github/workflows/continuous-delivery.yml @@ -108,9 +108,17 @@ jobs: tags: "${{ needs.release_amd64.outputs.tags }},${{ needs.release_386.outputs.tags }},${{ needs.release_arm64.outputs.tags }},${{ needs.release_arm_v7.outputs.tags }}" alternate_registry: thecodingmachine + - name: Merge AWS Lambda + uses: ./.github/actions/merge + with: + docker_hub_username: ${{ secrets.DOCKERHUB_USERNAME }} + docker_hub_password: ${{ secrets.DOCKERHUB_TOKEN }} + tags: "${{ needs.release_amd64.outputs.tags_aws_lambda }},${{ needs.release_arm64.outputs.tags_aws_lambda }}" + alternate_registry: thecodingmachine + - name: Clean uses: ./.github/actions/clean with: docker_hub_username: ${{ secrets.DOCKERHUB_USERNAME }} docker_hub_password: ${{ secrets.DOCKERHUB_TOKEN }} - tags: "${{ needs.release_amd64.outputs.tags }},${{ needs.release_386.outputs.tags }},${{ needs.release_arm64.outputs.tags }},${{ needs.release_arm_v7.outputs.tags }}" + tags: "${{ needs.release_amd64.outputs.tags }},${{ needs.release_386.outputs.tags }},${{ needs.release_arm64.outputs.tags }},${{ needs.release_arm_v7.outputs.tags }},${{ needs.release_amd64.outputs.tags_aws_lambda }},${{ needs.release_arm64.outputs.tags_aws_lambda }}" diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index b13dec5d..e4c6708e 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -202,12 +202,19 @@ jobs: docker_hub_password: ${{ secrets.DOCKERHUB_TOKEN }} tags: "${{ needs.snapshot_amd64.outputs.tags }},${{ needs.snapshot_386.outputs.tags }},${{ needs.snapshot_arm64.outputs.tags }},${{ needs.snapshot_arm_v7.outputs.tags }}" + - name: Merge AWS Lambda + uses: ./.github/actions/merge + with: + docker_hub_username: ${{ secrets.DOCKERHUB_USERNAME }} + docker_hub_password: ${{ secrets.DOCKERHUB_TOKEN }} + tags: "${{ needs.snapshot_amd64.outputs.tags_aws_lambda }},${{ needs.snapshot_arm64.outputs.tags_aws_lambda }}" + - name: Clean uses: ./.github/actions/clean with: docker_hub_username: ${{ secrets.DOCKERHUB_USERNAME }} docker_hub_password: ${{ secrets.DOCKERHUB_TOKEN }} - tags: "${{ needs.snapshot_amd64.outputs.tags }},${{ needs.snapshot_386.outputs.tags }},${{ needs.snapshot_arm64.outputs.tags }},${{ needs.snapshot_arm_v7.outputs.tags }}" + tags: "${{ needs.snapshot_amd64.outputs.tags }},${{ needs.snapshot_386.outputs.tags }},${{ needs.snapshot_arm64.outputs.tags }},${{ needs.snapshot_arm_v7.outputs.tags }},${{ needs.snapshot_amd64.outputs.tags_aws_lambda }},${{ needs.snapshot_arm64.outputs.tags_aws_lambda }}" edge_amd64: if: github.event_name == 'push' && github.ref == 'refs/heads/main' @@ -317,9 +324,17 @@ jobs: tags: "${{ needs.edge_amd64.outputs.tags }},${{ needs.edge_386.outputs.tags }},${{ needs.edge_arm64.outputs.tags }},${{ needs.edge_arm_v7.outputs.tags }}" alternate_registry: thecodingmachine + - name: Merge AWS Lambda + uses: ./.github/actions/merge + with: + docker_hub_username: ${{ secrets.DOCKERHUB_USERNAME }} + docker_hub_password: ${{ secrets.DOCKERHUB_TOKEN }} + tags: "${{ needs.edge_amd64.outputs.tags_aws_lambda }},${{ needs.edge_arm64.outputs.tags_aws_lambda }}" + alternate_registry: thecodingmachine + - name: Clean uses: ./.github/actions/clean with: docker_hub_username: ${{ secrets.DOCKERHUB_USERNAME }} docker_hub_password: ${{ secrets.DOCKERHUB_TOKEN }} - tags: "${{ needs.edge_amd64.outputs.tags }},${{ needs.edge_386.outputs.tags }},${{ needs.edge_arm64.outputs.tags }},${{ needs.edge_arm_v7.outputs.tags }}" + tags: "${{ needs.edge_amd64.outputs.tags }},${{ needs.edge_386.outputs.tags }},${{ needs.edge_arm64.outputs.tags }},${{ needs.edge_arm_v7.outputs.tags }},${{ needs.edge_amd64.outputs.tags_aws_lambda }},${{ needs.edge_arm64.outputs.tags_aws_lambda }}"