|
| 1 | +name: "Build and Push Simple Docker Image" |
| 2 | +description: "Reusable action to build and push a Docker image for any repo, with simple platform/version args." |
| 3 | +inputs: |
| 4 | + docker_username: |
| 5 | + description: "DockerHub Username" |
| 6 | + required: true |
| 7 | + docker_password: |
| 8 | + description: "DockerHub Password" |
| 9 | + required: true |
| 10 | + github_token: |
| 11 | + description: "GitHub Token for GitHub Container Registry" |
| 12 | + required: true |
| 13 | + platforms: |
| 14 | + description: "Target platforms (comma-separated, e.g. linux/amd64,linux/arm64)" |
| 15 | + required: false |
| 16 | + default: "linux/amd64,linux/arm64" |
| 17 | + version: |
| 18 | + description: "Image version tag (optional)" |
| 19 | + required: false |
| 20 | + default: "" |
| 21 | +runs: |
| 22 | + using: "composite" |
| 23 | + steps: |
| 24 | + - name: Login to DockerHub |
| 25 | + uses: docker/login-action@v3 |
| 26 | + with: |
| 27 | + username: ${{ inputs.docker_username }} |
| 28 | + password: ${{ inputs.docker_password }} |
| 29 | + - name: Login to GitHub Container Registry |
| 30 | + uses: docker/login-action@v3 |
| 31 | + with: |
| 32 | + registry: ghcr.io |
| 33 | + username: ${{ github.actor }} |
| 34 | + password: ${{ inputs.github_token }} |
| 35 | + - name: Set up Docker Buildx |
| 36 | + uses: docker/setup-buildx-action@v3 |
| 37 | + - name: Build and Push Docker Image |
| 38 | + uses: docker/build-push-action@v6 |
| 39 | + with: |
| 40 | + context: . |
| 41 | + file: ./Containerfile |
| 42 | + platforms: ${{ inputs.platforms }} |
| 43 | + push: true |
| 44 | + tags: | |
| 45 | + ghcr.io/${{ github.repository }}${{ inputs.version && format(':{}', inputs.version) || '' }} |
| 46 | + docker.io/${{ github.repository }}${{ inputs.version && format(':{}', inputs.version) || '' }} |
0 commit comments