--- name: "Docker builder" description: "Build and push container images using docker" author: Yi-Ting Shih inputs: context: description: "The context of the build environment" required: false default: . file: description: "The file location of Dockerfile" required: false default: ./Dockerfile target: description: "The target in Dockerfile" required: false default: '' push: description: "Whether the container will be pushed or not" required: false default: true push-registry: description: "The registry to push to" required: false default: gitea.konchin.com cache: description: "Whether the container will be cached or not" required: false default: true registry-certificate: description: "The certificate for registry" required: false username: description: "The username of the user to use when push" required: false password: description: "The password of the user to use when push" required: false outputs: imageid: description: "Image Id" value: ${{ steps.build.outputs.imageid }} digest: description: "Image digest" value: ${{ steps.build.outputs.digest }} runs: using: composite steps: - name: Checkout repository uses: actions/checkout@v4.2.2 - name: Setup env run: | echo "$GITHUB_REPOSITORY" echo "GITEA_REPO=${GITHUB_REPOSITORY}" | \ tr '[:upper:]' '[:lower:]' >> $GITHUB_ENV - name: Setup docker qemu uses: docker/setup-qemu-action@v3.6.0 - name: Setup Root CA run: | echo "${{ inputs.registry-certificate }}" | tee rootca.pem - name: Setup Docker BuildX uses: docker/setup-buildx-action@v3.10.0 with: #buildkitd-flags: --debug config-inline: | [registry."${{ inputs.push-registry }}"] ca = ["rootca.pem"] - name: Login to registry uses: docker/login-action@v3.4.0 with: registry: ${{ inputs.push-registry }} username: ${{ inputs.username }} password: ${{ inputs.password }} - name: Setup metadata id: meta uses: docker/metadata-action@v5.7.0 env: NODE_OPTIONS: --use-openssl-ca with: context: workflow images: | ${{ inputs.push-registry }}/${{ env.GITEA_REPO }} tags: | type=raw,value=latest,enable={{is_default_branch}} type=ref,event=branch type=ref,event=tag type=sha - name: Build and push with docker id: build uses: docker/build-push-action@v6.15.0 env: DOCKER_BUILD_SUMMARY: false ACTIONS_RUNTIME_TOKEN: '' with: context: ${{ inputs.context }} file: ${{ inputs.file }} target: ${{ inputs.target }} platforms: linux/amd64 push: true tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} cache-from: | type=registry,ref=${{ inputs.push-registry }}/${{ env.GITEA_REPO }}/cache cache-to: | type=registry,mode=max,image-manifest=true,oci-mediatypes=true,ref=${{ inputs.push-registry }}/${{ env.GITEA_REPO }}/cache