|
| 1 | +name: Build multi-arch image |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_call: |
| 5 | + inputs: |
| 6 | + version: |
| 7 | + description: 'The version build matrix as an escaped JSON string.' |
| 8 | + required: true |
| 9 | + type: string |
| 10 | + arch: |
| 11 | + description: 'The architecture build matrix as an escaped JSON string.' |
| 12 | + required: true |
| 13 | + type: string |
| 14 | + secrets: |
| 15 | + dockerhub_username: |
| 16 | + description: 'The username for Dockerhub.' |
| 17 | + required: false |
| 18 | + dockerhub_password: |
| 19 | + description: 'The password for Dockerhub.' |
| 20 | + required: false |
| 21 | + |
| 22 | +jobs: |
| 23 | + |
| 24 | + # ----------------------------------------------------------------------------------------------- |
| 25 | + # JOB 1: CONFIGURE |
| 26 | + # ----------------------------------------------------------------------------------------------- |
| 27 | + configure: |
| 28 | + name: Configure Build |
| 29 | + runs-on: ubuntu-latest |
| 30 | + outputs: |
| 31 | + can_login: ${{ steps.checksecret_job.outputs.is_MY_SECRET_set }} |
| 32 | + steps: |
| 33 | + - name: Eval login and push |
| 34 | + id: check_secrets |
| 35 | + env: |
| 36 | + ENV_USER: ${{ secrets.dockerhub_username }} |
| 37 | + ENV_PASS: ${{ secrets.dockerhub_password }} |
| 38 | + shell: bash |
| 39 | + run: | |
| 40 | + if [ "${{ env.USER }}" = '' ] || [ "${{ env.PASS }}" = '' ]; then |
| 41 | + echo "::set-output name=can_login::0" |
| 42 | + echo "can_login=0" |
| 43 | + else |
| 44 | + echo "::set-output name=can_login::1" |
| 45 | + echo "can_login=1" |
| 46 | + fi |
| 47 | +
|
| 48 | + # ----------------------------------------------------------------------------------------------- |
| 49 | + # JOB 2: BUILD |
| 50 | + # ----------------------------------------------------------------------------------------------- |
| 51 | + build: |
| 52 | + needs: [configure] |
| 53 | + name: Build ${{ input.name }}-${{ matrix.version }} (${{ matrix.arch }}) |
| 54 | + runs-on: ubuntu-latest |
| 55 | + strategy: |
| 56 | + fail-fast: false |
| 57 | + matrix: |
| 58 | + version: |
| 59 | + - ${{ fromJson(input.version) }} |
| 60 | + arch: |
| 61 | + - ${{ fromJson(input.arch) }} |
| 62 | + steps: |
| 63 | + |
| 64 | + # ------------------------------------------------------------ |
| 65 | + # Setup repository |
| 66 | + # ------------------------------------------------------------ |
| 67 | + - name: "[SETUP] Checkout repository" |
| 68 | + uses: actions/checkout@v2 |
| 69 | + with: |
| 70 | + fetch-depth: 0 |
| 71 | + |
| 72 | + - name: "[SETUP] Setup QEMU environment" |
| 73 | + uses: docker/setup-qemu-action@v1 |
| 74 | + with: |
| 75 | + image: tonistiigi/binfmt:latest |
| 76 | + platforms: all |
| 77 | + |
| 78 | + - name: "[SETUP] Determine Docker tag" |
| 79 | + id: tag |
| 80 | + |
| 81 | + |
| 82 | + # ------------------------------------------------------------ |
| 83 | + # Build |
| 84 | + # ------------------------------------------------------------ |
| 85 | + - name: Build |
| 86 | + |
| 87 | + with: |
| 88 | + command: | |
| 89 | + make build ARCH=${{ matrix.arch }} |
| 90 | +
|
| 91 | + # ------------------------------------------------------------ |
| 92 | + # Test |
| 93 | + # ------------------------------------------------------------ |
| 94 | + - name: Test |
| 95 | + |
| 96 | + with: |
| 97 | + command: | |
| 98 | + make test ARCH=${{ matrix.arch }} |
| 99 | +
|
| 100 | + # ------------------------------------------------------------ |
| 101 | + # Deploy |
| 102 | + # ------------------------------------------------------------ |
| 103 | + - name: Docker login |
| 104 | + uses: docker/login-action@v1 |
| 105 | + with: |
| 106 | + username: ${{ secrets.dockerhub_username }} |
| 107 | + password: ${{ secrets.dockerhub_password }} |
| 108 | + if: needs.configure.outputs.can_login == '1' |
| 109 | + |
| 110 | + - name: Docker push architecture image |
| 111 | + |
| 112 | + with: |
| 113 | + command: | |
| 114 | + make push-arch TAG=${{ steps.tag.outputs.docker-tag }} ARCH=${{ matrix.arch }} |
| 115 | + if: needs.configure.outputs.can_login == '1' |
0 commit comments