From 09990df1e001db7b8907e48f63472ecdb7e27efb Mon Sep 17 00:00:00 2001 From: bbharathkumarreddy Date: Tue, 4 Jun 2024 23:47:36 +0530 Subject: [PATCH] Add Docker Qemu build action --- .gitignore | 0 LICENSE | 2 +- README.md | 45 +++++++++++++++++++++++++++++++++++ action.yml | 70 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 116 insertions(+), 1 deletion(-) create mode 100644 .gitignore create mode 100644 action.yml diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e69de29 diff --git a/LICENSE b/LICENSE index 261eeb9..a497d8f 100644 --- a/LICENSE +++ b/LICENSE @@ -186,7 +186,7 @@ same "printed page" as the copyright notice for easier identification within third-party archives. - Copyright [yyyy] [name of copyright owner] + Copyright [2024] [bbharathkumarreddy96@gmail.com] Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/README.md b/README.md index 93601ec..be5bb35 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,47 @@ # docker-qemu-buildx-ecr-action + Docker QEMU Buildx ECR Action - supports multi platform builds including linux/arm64 and ECR Push + +## Usage + +```yaml +name: ci + +on: + push: + +jobs: + qemu: + runs-on: ubuntu-latest + steps: + - name: Docker QEMU Buildx ECR + uses: bbharathkumarreddy/docker-qemu-buildx-ecr-action + with: + platform: linux/arm64 + ecr-push: true + aws-access-key-id: ${{ secrets.aws-access-key-id }} + aws-secret-access-key: ${{ secrets.aws-secret-access-key }} + aws-region: ${{ vars.aws-region }} + ecr-repository: my-service + ecr-tag: latest +``` + +## Customizing + +### inputs + +The following inputs can be used as `step.with` keys: + +| Name | Type | Default | Description | +| ----------------------- | ------- | ----------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------ | +| `platform` | String | [`linux/arm64`](https://docs.docker.com/build/building/multi-platform/) | Platform architecture to build. | +| `ecr-push` | Boolean | `true` | Set to `true` to push the docker build to ECR repository. `aws.*` and `ecr.*` inputs to be given if set to `true`. | +| `aws-access-key-id` | String | | Pass the AWS access key id. | +| `aws-secret-access-key` | String | | Pass the AWS secret access key. | +| `aws-region` | String | | Pass the AWS region of the ECR repository. | +| `ecr-repository` | String | | Pass the ECR repository name. | +| `ecr-tag` | String | `latest` | Pass ECR tag to push. | + +## Contributing + +Want to contribute? ✅ diff --git a/action.yml b/action.yml new file mode 100644 index 0000000..fb11205 --- /dev/null +++ b/action.yml @@ -0,0 +1,70 @@ +name: "Docker QEMU Buildx ECR Action" +description: "Docker QEMU Buildx ECR Action - supports multi platform builds including linux/arm64 and ECR Push" +author: "bbharathkumarreddy@96@gmail.com" +branding: + icon: "package" + color: "blue" + +inputs: + platform: + description: "Platform architecture to build." + default: "linux/arm64" + required: false + ecr-push: + description: "ECR push." + default: "true" + required: false + aws-access-key-id: + description: "AWS access key id." + required: false + aws-secret-access-key: + description: "AWS Secret access key." + required: false + aws-region: + description: "AWS region of the ECR repository." + required: false + ecr-repository: + description: "ECR repository name." + required: false + ecr-tag: + description: "AWS region." + default: "latest" + required: false + +runs: + using: "composite" + steps: + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Configure AWS credentials + if: ${{ inputs.ecr-push == 'true' }} + uses: aws-actions/configure-aws-credentials@v4 + with: + aws-access-key-id: ${{ inputs.aws-access-key-id }} + aws-secret-access-key: ${{ inputs.aws-secret-access-key }} + aws-region: ${{ inputs.aws-region }} + + - name: Login to Amazon ECR + if: ${{ inputs.ecr-push == 'true' }} + id: login-ecr + uses: aws-actions/amazon-ecr-login@v2 + + - name: ECR Build and push + uses: docker/build-push-action@v5 + env: + ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }} + ECR_REPOSITORY: ${{ inputs.ecr-repository }} + IMAGE_TAG: ${{ inputs.ecr-tag }} + AWS_REGION: ${{ inputs.aws-region }} + with: + push: ${{ inputs.ecr-push }} + context: . + platforms: ${{ inputs.platform }} + tags: ${{ env.ECR_REGISTRY }}/${{ env.ECR_REPOSITORY }}:${{ env.IMAGE_TAG }} + provenance: false + cache-from: type=gha + cache-to: type=gha,mode=max