|
| 1 | +name: Docker Build |
| 2 | +description: 'Build and push a Docker image to the registry' |
| 3 | + |
| 4 | +inputs: |
| 5 | + repository: |
| 6 | + description: 'The name of the repository to build' |
| 7 | + required: true |
| 8 | + dockerfile: |
| 9 | + description: 'The name of the Dockerfile to build' |
| 10 | + required: true |
| 11 | + push: |
| 12 | + description: 'Whether to push the image to the registry' |
| 13 | + required: false |
| 14 | + default: false |
| 15 | + minify: |
| 16 | + description: 'Whether to minify the build' |
| 17 | + required: false |
| 18 | + default: true |
| 19 | + tag: |
| 20 | + description: 'Optional Docker tag' |
| 21 | + required: false |
| 22 | + default: '' |
| 23 | + depot-project: |
| 24 | + description: 'Depot project ID (required if no depot.json; get it from depot.dev)' |
| 25 | + required: false |
| 26 | + default: '' |
| 27 | + |
| 28 | +runs: |
| 29 | + using: 'composite' |
| 30 | + steps: |
| 31 | + - uses: aws-actions/configure-aws-credentials@v3 |
| 32 | + with: |
| 33 | + role-session-name: container_pusher |
| 34 | + role-to-assume: arn:aws:iam::986677156374:role/actions/build/container_pusher |
| 35 | + aws-region: us-east-1 |
| 36 | + |
| 37 | + - uses: aws-actions/amazon-ecr-login@v1 |
| 38 | + id: ecr |
| 39 | + with: |
| 40 | + mask-password: true |
| 41 | + |
| 42 | + - uses: docker/metadata-action@v4 |
| 43 | + id: meta |
| 44 | + with: |
| 45 | + images: ${{ steps.ecr.outputs.registry }}/${{ inputs.repository }} |
| 46 | + flavor: | |
| 47 | + latest=false |
| 48 | + tags: | |
| 49 | + type=raw,enable=${{ inputs.tag != '' }},value=${{ inputs.tag }} |
| 50 | + type=semver,pattern={{version}} |
| 51 | + type=sha,enable=${{ !startsWith(github.ref, 'refs/tags') }},prefix=,format=long |
| 52 | +
|
| 53 | + - name: Set BUILD_DATE |
| 54 | + id: meta_date |
| 55 | + shell: bash |
| 56 | + run: | |
| 57 | + export TZ=America/Toronto |
| 58 | + echo "timestamp=$(date +"%Y-%m-%d %H:%M:%S")" >> "$GITHUB_OUTPUT" |
| 59 | +
|
| 60 | + - name: Create ECR Registry |
| 61 | + shell: bash |
| 62 | + env: |
| 63 | + ECR_REPOSITORY: ${{ inputs.repository }} |
| 64 | + ECR_REGISTRY: ${{ steps.ecr.outputs.registry }} |
| 65 | + run: | |
| 66 | + aws --version |
| 67 | + aws ecr create-repository --repository-name $ECR_REPOSITORY || true |
| 68 | + aws ssm get-parameter --name '/cloud/container-registry/ecr-policy-document' --query 'Parameter.Value' | jq -r > repository-policy.json |
| 69 | + aws ecr set-repository-policy --repository-name $ECR_REPOSITORY --policy-text file://repository-policy.json &> /dev/null |
| 70 | +
|
| 71 | + - name: Set up Depot CLI |
| 72 | + uses: depot/setup-action@v1 |
| 73 | + |
| 74 | + - uses: depot/build-push-action@v1 |
| 75 | + with: |
| 76 | + project: ${{ inputs.depot-project }} |
| 77 | + build-args: | |
| 78 | + MINIFY=${{ inputs.minify }} |
| 79 | + DOCKER_TAG=${{ inputs.tag }} |
| 80 | + BUILD_DATE=${{ steps.meta_date.outputs.timestamp }} |
| 81 | + file: ${{ inputs.dockerfile }} |
| 82 | + context: . |
| 83 | + push: ${{ inputs.push }} |
| 84 | + tags: ${{ steps.meta.outputs.tags }} |
| 85 | + labels: ${{ steps.meta.outputs.labels }} |
0 commit comments