|
| 1 | +name: 'Re-usable Docker Build Flow' |
| 2 | +description: 'Used to setup and build a docker image' |
| 3 | +inputs: |
| 4 | + scope: |
| 5 | + description: 'Turbo Repo scope to run the build for' |
| 6 | + required: true |
| 7 | + docker-repo-name: |
| 8 | + description: 'Docker name of the repo <account-id>.dkr.ecr.us-east-1.amazonaws.com/<name>' |
| 9 | + required: true |
| 10 | + app-path: |
| 11 | + description: 'The path of where the application is located in the monorepo ie servers/<app-name>' |
| 12 | + required: true |
| 13 | + context: |
| 14 | + description: 'The path of where to build from' |
| 15 | + required: true |
| 16 | + default: '.' |
| 17 | + app-port: |
| 18 | + description: 'The port the application runs on ie 80' |
| 19 | + required: true |
| 20 | + sentry-org: |
| 21 | + description: 'The org name used in sentry. Used to upload source maps' |
| 22 | + required: false |
| 23 | + default: pocket |
| 24 | + sentry-project: |
| 25 | + description: 'The project name used in sentry. Used to upload source maps' |
| 26 | + required: true |
| 27 | + sentry-token: |
| 28 | + description: 'The token used for sentry. Used to upload source maps' |
| 29 | + required: true |
| 30 | + release-version: |
| 31 | + description: 'The release version to use in build' |
| 32 | + required: true |
| 33 | + assets-prefix: |
| 34 | + description: 'The assets prefix to build with' |
| 35 | + required: false |
| 36 | + s3-bucket: |
| 37 | + description: 'The s3 bucket to upload assets to' |
| 38 | + required: false |
| 39 | + s3-path: |
| 40 | + description: 'The s3 path to upload assets to' |
| 41 | + required: false |
| 42 | + push: |
| 43 | + description: Whether or not to push the image |
| 44 | + required: true |
| 45 | + default: 'false' |
| 46 | + dockerhub-username: |
| 47 | + description: Docker hub username |
| 48 | + required: true |
| 49 | + dockerhub-token: |
| 50 | + description: Dockerhub Token |
| 51 | + required: true |
| 52 | + |
| 53 | + |
| 54 | +outputs: |
| 55 | + docker-image-name: |
| 56 | + description: The full name with registry of the built docker image |
| 57 | + value: ${{ steps.get-build-name.outputs.docker-image-name }} |
| 58 | + |
| 59 | +runs: |
| 60 | + using: 'composite' |
| 61 | + steps: |
| 62 | + # can be useful if you want to add emulation support with QEMU to be able to build against more platforms. |
| 63 | + - name: Set up QEMU |
| 64 | + uses: docker/setup-qemu-action@v3 |
| 65 | + |
| 66 | + # action will create and boot a builder using by default the docker-container driver. |
| 67 | + # This is not required but recommended using it to be able to build multi-platform images, export cache, etc. |
| 68 | + - name: Set up Docker Buildx |
| 69 | + uses: docker/setup-buildx-action@v3 |
| 70 | + |
| 71 | + - name: Login to Docker Hub |
| 72 | + uses: docker/login-action@v3 |
| 73 | + with: |
| 74 | + username: ${{ inputs.dockerhub-username }} |
| 75 | + password: ${{ inputs.dockerhub-token }} |
| 76 | + |
| 77 | + - name: Login to Amazon ECR |
| 78 | + if: inputs.push == 'true' |
| 79 | + uses: aws-actions/amazon-ecr-login@v2 |
| 80 | + |
| 81 | + - name: Build docker image |
| 82 | + id: docker-build-push |
| 83 | + uses: docker/build-push-action@v6 |
| 84 | + with: |
| 85 | + push: ${{inputs.push}} |
| 86 | + tags: ${{inputs.docker-repo-name}}:${{ github.sha }} |
| 87 | + context: ${{ inputs.context }} |
| 88 | + build-args: | |
| 89 | + GIT_SHA=${{ github.sha }} |
| 90 | + SCOPE=${{inputs.scope}} |
| 91 | + APP_PATH=${{inputs.app-path}} |
| 92 | + SENTRY_ORG=${{inputs.sentry-org}} |
| 93 | + SENTRY_PROJECT=${{inputs.sentry-project}} |
| 94 | + PORT=${{inputs.app-port}} |
| 95 | + RELEASE_VERSION=${{inputs.release-version}} |
| 96 | + ASSET_PREFIX=${{inputs.assets-prefix}} |
| 97 | + S3_BUCKET=${{inputs.s3-bucket}} |
| 98 | + S3_PATH=${{inputs.s3-path}} |
| 99 | + secrets: | |
| 100 | + aws-access-key-id=${{ env.AWS_ACCESS_KEY_ID }} |
| 101 | + aws-secret-access-key=${{ env.AWS_SECRET_ACCESS_KEY }} |
| 102 | + aws-session-token=${{ env.AWS_SESSION_TOKEN }} |
| 103 | + aws-region=${{ env.AWS_REGION }} |
| 104 | + - name: Output Build Name |
| 105 | + id: get-build-name |
| 106 | + shell: bash |
| 107 | + run: | |
| 108 | + echo "docker-image-name=${{inputs.docker-repo-name}}:${{ github.sha }}" >> $GITHUB_OUTPUT |
0 commit comments