|
| 1 | +name: "Docker Action" |
| 2 | +description: "Build or Merge Docker images using the repository's Makefile." |
| 3 | +inputs: |
| 4 | + operation: |
| 5 | + description: "The operation to perform (build or merge)" |
| 6 | + required: true |
| 7 | + target: |
| 8 | + description: "The Makefile target to run" |
| 9 | + required: true |
| 10 | + docker_user: |
| 11 | + description: "DockerHub username" |
| 12 | + required: true |
| 13 | + default: "kpango" |
| 14 | + docker_pass: |
| 15 | + description: "DockerHub password" |
| 16 | + required: true |
| 17 | + github_token: |
| 18 | + description: "GitHub Token" |
| 19 | + required: true |
| 20 | + docker_push: |
| 21 | + description: "Whether this is a push build" |
| 22 | + required: false |
| 23 | + default: "false" |
| 24 | + platform: |
| 25 | + description: "The platform to build" |
| 26 | + required: false |
| 27 | + suffix: |
| 28 | + description: "The suffix for the docker tag" |
| 29 | + required: false |
| 30 | + ghcr_user: |
| 31 | + description: "GHCR username" |
| 32 | + required: false |
| 33 | + default: ${{ github.repository_owner }} |
| 34 | + |
| 35 | +runs: |
| 36 | + using: "composite" |
| 37 | + steps: |
| 38 | + - name: Set up QEMU |
| 39 | + if: inputs.operation == 'build' |
| 40 | + uses: docker/setup-qemu-action@v4 |
| 41 | + with: |
| 42 | + image: tonistiigi/binfmt:master |
| 43 | + |
| 44 | + - name: Login to DockerHub |
| 45 | + if: inputs.operation == 'merge' || inputs.docker_push == 'true' |
| 46 | + uses: docker/login-action@v4 |
| 47 | + with: |
| 48 | + username: ${{ inputs.docker_user }} |
| 49 | + password: ${{ inputs.docker_pass }} |
| 50 | + |
| 51 | + - name: Login to GitHub Container Registry |
| 52 | + if: inputs.operation == 'merge' || inputs.docker_push == 'true' |
| 53 | + uses: docker/login-action@v4 |
| 54 | + with: |
| 55 | + registry: ghcr.io |
| 56 | + username: ${{ github.actor }} |
| 57 | + password: ${{ inputs.github_token }} |
| 58 | + |
| 59 | + - name: Create Buildx |
| 60 | + if: inputs.operation == 'build' |
| 61 | + shell: bash |
| 62 | + env: |
| 63 | + GITHUB_ACCESS_TOKEN: ${{ inputs.github_token }} |
| 64 | + DOCKER_BUILDER_PLATFORM: ${{ inputs.platform }} |
| 65 | + run: | |
| 66 | + make \ |
| 67 | + DOCKER_BUILDER_PLATFORM="$DOCKER_BUILDER_PLATFORM" \ |
| 68 | + GITHUB_ACCESS_TOKEN="$GITHUB_ACCESS_TOKEN" \ |
| 69 | + create_buildx |
| 70 | +
|
| 71 | + - name: Run Makefile target |
| 72 | + shell: bash |
| 73 | + env: |
| 74 | + OPERATION: ${{ inputs.operation }} |
| 75 | + TARGET: ${{ inputs.target }} |
| 76 | + USER_DEFAULT: ${{ inputs.docker_user }} |
| 77 | + GHCR_USER: ${{ inputs.ghcr_user }} |
| 78 | + DOCKER_PUSH: ${{ inputs.docker_push }} |
| 79 | + GITHUB_ACCESS_TOKEN: ${{ inputs.github_token }} |
| 80 | + DOCKER_BUILDER_PLATFORM: ${{ inputs.platform }} |
| 81 | + DOCKER_ARCH_SUFFIX: ${{ inputs.suffix }} |
| 82 | + EVENT_NAME: ${{ github.event_name }} |
| 83 | + EVENT_PATH: ${{ github.event_path }} |
| 84 | + GITHUB_REF_VAR: ${{ github.ref }} |
| 85 | + run: | |
| 86 | + VERSION="nightly" |
| 87 | +
|
| 88 | + if [ "$EVENT_NAME" == "pull_request" ]; then |
| 89 | + PR_NUM=$(jq -r ".number" "$EVENT_PATH") |
| 90 | + VERSION="pr-$PR_NUM" |
| 91 | + elif [[ "$GITHUB_REF_VAR" == refs/tags/* ]]; then |
| 92 | + VERSION="${GITHUB_REF_VAR#refs/tags/}" |
| 93 | + fi |
| 94 | +
|
| 95 | + if [ "$OPERATION" == "build" ]; then |
| 96 | + make \ |
| 97 | + DOCKER_PUSH="$DOCKER_PUSH" \ |
| 98 | + USER="$USER_DEFAULT" \ |
| 99 | + SYS_USER="$USER_DEFAULT" \ |
| 100 | + USER_ID="1000" \ |
| 101 | + GROUP_ID="1000" \ |
| 102 | + GROUP_IDS="1000 98 972 987 994 996 998 1001 1002 1003 1004 1005" \ |
| 103 | + GHCR_USER="$GHCR_USER" \ |
| 104 | + VERSION="$VERSION" \ |
| 105 | + GITHUB_ACCESS_TOKEN="$GITHUB_ACCESS_TOKEN" \ |
| 106 | + DOCKER_BUILDER_PLATFORM="$DOCKER_BUILDER_PLATFORM" \ |
| 107 | + DOCKER_ARCH_SUFFIX="$DOCKER_ARCH_SUFFIX" \ |
| 108 | + "$TARGET" |
| 109 | + else |
| 110 | + make \ |
| 111 | + USER="$USER_DEFAULT" \ |
| 112 | + GHCR_USER="$GHCR_USER" \ |
| 113 | + VERSION="$VERSION" \ |
| 114 | + "$TARGET" |
| 115 | + fi |
0 commit comments