-
-
Notifications
You must be signed in to change notification settings - Fork 6
Use proposed GitHub action workflow for testing #164
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,154 @@ | ||
| name: Build and Push Docker image | ||
|
|
||
| on: | ||
| workflow_call: | ||
| inputs: | ||
| aws_ecr: | ||
| description: "Push to AWS ECR" | ||
| default: true | ||
| required: false | ||
| type: boolean | ||
| docker_hub: | ||
| description: "Push to Docker Hub" | ||
| default: true | ||
| required: false | ||
| type: boolean | ||
| provenance: | ||
| description: "Generate provenance attestation for the build" | ||
| default: true | ||
| required: false | ||
| type: boolean | ||
| image_name: | ||
| description: "The name of the image to deploy (default: repo name)" | ||
| required: false | ||
| type: string | ||
| platform: | ||
| description: "The image's platform (default: linux/amd64)" | ||
| default: "linux/amd64" | ||
| required: false | ||
| type: string | ||
| secrets: | ||
| AWS_ACCOUNT_ID: | ||
| description: "The AWS account ID used to determine the ECR registry" | ||
| required: true | ||
| AWS_REGION: | ||
| description: "The AWS region used to determine the ECR registry" | ||
| required: true | ||
| AWS_ECR_ACCESS_KEY_ID: | ||
| description: "The access key ID used to log into AWS ECR" | ||
| required: true | ||
| AWS_ECR_SECRET_ACCESS_KEY: | ||
| description: "The secret access key ID used to log into AWS ECR" | ||
| required: true | ||
| DOCKERHUB_USERNAME: | ||
| description: "The username used to log into Docker Hub" | ||
| required: true | ||
| DOCKERHUB_PASSWORD: | ||
| description: "The password used to log into Docker Hub" | ||
| required: true | ||
| DOCKER_BUILD_ARGS: | ||
| description: "Docker build arguments" | ||
| required: false | ||
|
|
||
| permissions: | ||
| contents: write | ||
|
|
||
| jobs: | ||
| build-and-push: | ||
| runs-on: ubuntu-22.04 | ||
|
|
||
| env: | ||
| ECR_REGISTRY: ${{ secrets.AWS_ACCOUNT_ID }}.dkr.ecr.${{ secrets.AWS_REGION }}.amazonaws.com | ||
|
|
||
| steps: | ||
| - name: Checkout code | ||
| uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 | ||
| with: | ||
| # Never deploy from non-main branches | ||
| ref: main | ||
|
|
||
| - name: Check if Dockerfile is present | ||
| id: dockerfile-exists | ||
| run: | | ||
| dockerfile_exists=$(test -f Dockerfile && echo 'true' || echo 'false') | ||
| if [ "${dockerfile_exists}" == "false" ]; then | ||
| echo "::warning:: Skip deploy due to missing Dockerfile" | ||
| fi | ||
| echo "result=${dockerfile_exists}" >> $GITHUB_OUTPUT | ||
|
|
||
| - name: Set up Docker | ||
| uses: docker/setup-docker-action@v4 | ||
| with: | ||
| daemon-config: | | ||
| { | ||
| "features": { | ||
| "containerd-snapshotter": true | ||
| } | ||
| } | ||
|
|
||
| - name: Set up QEMU | ||
| uses: docker/setup-qemu-action@v3 | ||
|
|
||
| - name: Set up Docker Buildx | ||
| if: steps.dockerfile-exists.outputs.result == 'true' | ||
| uses: docker/setup-buildx-action@e468171a9de216ec08956ac3ada2f0791b6bd435 | ||
|
|
||
| - name: Login to DockerHub | ||
| uses: docker/login-action@5e57cd118135c172c3672efd75eb46360885c0ef | ||
| if: ${{steps.dockerfile-exists.outputs.result == 'true' && inputs.docker_hub}} | ||
| with: | ||
| username: ${{ secrets.DOCKERHUB_USERNAME }} | ||
| password: ${{ secrets.DOCKERHUB_PASSWORD }} | ||
|
|
||
| - name: Login to ECR | ||
| uses: docker/login-action@5e57cd118135c172c3672efd75eb46360885c0ef | ||
| if: ${{steps.dockerfile-exists.outputs.result == 'true' && inputs.aws_ecr}} | ||
| with: | ||
| registry: ${{ env.ECR_REGISTRY }} | ||
| username: ${{ secrets.AWS_ECR_ACCESS_KEY_ID }} | ||
| password: ${{ secrets.AWS_ECR_SECRET_ACCESS_KEY }} | ||
|
|
||
| - name: Build Docker image | ||
| if: ${{steps.dockerfile-exists.outputs.result == 'true' && (inputs.docker_hub || inputs.aws_ecr)}} | ||
| uses: docker/build-push-action@263435318d21b8e681c14492fe198d362a7d2c83 | ||
| with: | ||
| context: . | ||
| file: ./Dockerfile | ||
| load: true | ||
| cache-from: type=gha | ||
| cache-to: type=gha,mode=max | ||
| build-args: ${{ secrets.DOCKER_BUILD_ARGS }} | ||
| provenance: false | ||
| platforms: ${{ inputs.platform }} | ||
|
|
||
| - name: Push to Docker Hub | ||
| uses: docker/build-push-action@263435318d21b8e681c14492fe198d362a7d2c83 | ||
| if: ${{steps.dockerfile-exists.outputs.result == 'true' && inputs.docker_hub}} | ||
| with: | ||
| context: . | ||
| file: ./Dockerfile | ||
| push: true | ||
| tags: | | ||
| sencudra/${{ inputs.image_name || github.event.repository.name }}:latest | ||
| sencudra/${{ inputs.image_name || github.event.repository.name }}:${{ github.sha }} | ||
| cache-from: type=gha | ||
| cache-to: type=gha,mode=max | ||
| build-args: ${{ secrets.DOCKER_BUILD_ARGS }} | ||
| provenance: false | ||
| platforms: ${{ inputs.platform }} | ||
|
|
||
| - name: Push to AWS ECR | ||
| uses: docker/build-push-action@263435318d21b8e681c14492fe198d362a7d2c83 | ||
| if: ${{steps.dockerfile-exists.outputs.result == 'true' && inputs.aws_ecr}} | ||
| with: | ||
| context: . | ||
| file: ./Dockerfile | ||
| push: true | ||
| tags: | | ||
| ${{ env.ECR_REGISTRY }}/${{ inputs.image_name || github.event.repository.name }}:production | ||
| ${{ env.ECR_REGISTRY }}/${{ inputs.image_name || github.event.repository.name }}:${{ github.sha }} | ||
| cache-from: type=gha | ||
| cache-to: type=gha,mode=max | ||
| build-args: ${{ secrets.DOCKER_BUILD_ARGS }} | ||
| provenance: false | ||
| platforms: ${{ inputs.platform }} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of adding new workflow file, maybe it’s possible just to specify test branch here in replace to @main?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The test branch is not part of exercism/github-actions, but of your repository. I don't know if that could possibly work?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Never mind, yeah, it’s in my fork. Not safe at all.