|
| 1 | +name: Docker build |
| 2 | + |
| 3 | +# Controls when the workflow will run |
| 4 | +on: |
| 5 | + release: |
| 6 | + types: |
| 7 | + - published |
| 8 | + pull_request: |
| 9 | + branches: |
| 10 | + - main |
| 11 | + |
| 12 | +jobs: |
| 13 | + build: |
| 14 | + runs-on: ubuntu-latest |
| 15 | + |
| 16 | + strategy: |
| 17 | + fail-fast: false |
| 18 | + matrix: |
| 19 | + base: |
| 20 | + - alpine |
| 21 | + - fedora |
| 22 | + terraform: |
| 23 | + - v1.0 |
| 24 | + - v1.1 |
| 25 | + - v1.2 |
| 26 | + |
| 27 | + env: |
| 28 | + TERRAFORM_LATEST: "v1.2" |
| 29 | + |
| 30 | + steps: |
| 31 | + - name: Checkout |
| 32 | + uses: actions/checkout@v3 |
| 33 | + |
| 34 | + - name: Set up QEMU |
| 35 | + uses: docker/setup-qemu-action@v2 |
| 36 | + |
| 37 | + - name: Set up Docker Buildx |
| 38 | + id: buildx |
| 39 | + uses: docker/setup-buildx-action@v2 |
| 40 | + |
| 41 | + - name: Login to Docker Hub |
| 42 | + uses: docker/login-action@v2 |
| 43 | + with: |
| 44 | + username: ${{ secrets.DOCKER_USER }} |
| 45 | + password: ${{ secrets.DOCKER_TOKEN }} |
| 46 | + |
| 47 | + - name: Login to CNTK Quay |
| 48 | + uses: docker/login-action@v2 |
| 49 | + with: |
| 50 | + registry: quay.io |
| 51 | + username: ${{ secrets.QUAY_CNTK_USERNAME }} |
| 52 | + password: ${{ secrets.QUAY_CNTK_TOKEN }} |
| 53 | + |
| 54 | + - name: Setup variables ${{ matrix.base }}:${{ matrix.terraform }} |
| 55 | + id: variables |
| 56 | + shell: bash |
| 57 | + run: | |
| 58 | + SHORT_TERRAFORM=${{ matrix.terraform }} |
| 59 | + |
| 60 | + SHORT_TAG_ENABLED="false" |
| 61 | + if [[ "${{ matrix.base }}" == "alpine" ]]; then |
| 62 | + SHORT_TAG_ENABLED="true" |
| 63 | + fi |
| 64 | + |
| 65 | + BASE_ENABLED="false" |
| 66 | + LATEST_ENABLED="false" |
| 67 | + if [[ "${SHORT_TERRAFORM}" == "${TERRAFORM_LATEST}" ]]; then |
| 68 | + BASE_ENABLED="true" |
| 69 | + |
| 70 | + if [[ "${{ matrix.base }}" == "alpine" ]]; then |
| 71 | + LATEST_ENABLED="true" |
| 72 | + fi |
| 73 | + fi |
| 74 | + |
| 75 | + RELEASE_TAG=${GITHUB_REF#refs/tags/} |
| 76 | + RELEASE_TAG_ENABLED="false" |
| 77 | + RELEASE_TAG_SHORT_ENABLED="false" |
| 78 | + if [[ "${GITHUB_REF}" =~ refs/tags ]] && [[ "${RELEASE_TAG}" != "main" ]]; then |
| 79 | + RELEASE_TAG_ENABLED="true" |
| 80 | + |
| 81 | + if [[ "${{ matrix.base }}" == "alpine" ]]; then |
| 82 | + RELEASE_TAG_SHORT_ENABLED="true" |
| 83 | + fi |
| 84 | + else |
| 85 | + RELEASE_TAG="main" |
| 86 | + fi |
| 87 | + |
| 88 | + echo "Short terraform: ${SHORT_TERRAFORM}" |
| 89 | + echo "::set-output name=terraform::$SHORT_TERRAFORM" |
| 90 | + |
| 91 | + echo "Short tag enabled: $SHORT_TAG_ENABLED" |
| 92 | + echo "::set-output name=short-enabled::$SHORT_TAG_ENABLED" |
| 93 | + |
| 94 | + echo "Release tag: ${RELEASE_TAG}" |
| 95 | + echo "::set-output name=release-tag::$RELEASE_TAG" |
| 96 | + |
| 97 | + echo "Release tag enabled: $RELEASE_TAG_ENABLED" |
| 98 | + echo "::set-output name=release-tag-enabled::$RELEASE_TAG_ENABLED" |
| 99 | + |
| 100 | + echo "Release tag short enabled: $RELEASE_TAG_SHORT_ENABLED" |
| 101 | + echo "::set-output name=release-tag-short-enabled::$RELEASE_TAG_SHORT_ENABLED" |
| 102 | + |
| 103 | + echo "Base enabled: $BASE_ENABLED" |
| 104 | + echo "::set-output name=base-enabled::$BASE_ENABLED" |
| 105 | + |
| 106 | + echo "Latest enabled: $LATEST_ENABLED" |
| 107 | + echo "::set-output name=latest-enabled::$LATEST_ENABLED" |
| 108 | +
|
| 109 | + - name: Docker CNTK meta ${{ matrix.base }}:${{ matrix.terraform }} |
| 110 | + id: cntk-meta |
| 111 | + uses: docker/metadata-action@v4 |
| 112 | + with: |
| 113 | + # list of Docker images to use as base name for tags |
| 114 | + images: | |
| 115 | + quay.io/cloudnativetoolkit/cli-tools-core |
| 116 | + # Docker tags based on the following events/attributes |
| 117 | + tags: | |
| 118 | + type=raw,value=${{ steps.variables.outputs.terraform }}-${{ matrix.base }} |
| 119 | + type=raw,value=${{ steps.variables.outputs.terraform }},enable=${{ steps.variables.outputs.short-enabled }} |
| 120 | + type=raw,value=${{ steps.variables.outputs.terraform }}-${{ steps.variables.outputs.release-tag }}-${{ matrix.base }},enable=${{ steps.variables.outputs.release-tag-enabled }} |
| 121 | + type=raw,value=${{ steps.variables.outputs.terraform }}-${{ steps.variables.outputs.release-tag }},enable=${{ steps.variables.outputs.release-tag-short-enabled }} |
| 122 | + type=raw,value=${{ matrix.base }},enable=${{ steps.variables.outputs.base-enabled }} |
| 123 | + type=raw,value=latest,enable=${{ steps.variables.outputs.latest-enabled }} |
| 124 | +
|
| 125 | + - name: Build and push ${{ matrix.base }}:${{ matrix.terraform }} |
| 126 | + uses: docker/build-push-action@v3 |
| 127 | + with: |
| 128 | + context: . |
| 129 | + file: Dockerfile-${{ matrix.base }} |
| 130 | + build-args: | |
| 131 | + TERRAFORM_VERSION=${{ matrix.terraform }} |
| 132 | + push: ${{ github.event_name != 'pull_request' }} |
| 133 | + platforms: linux/amd64,linux/arm64 |
| 134 | + tags: ${{ steps.cntk-meta.outputs.tags }} |
| 135 | + labels: ${{ steps.cntk-meta.outputs.labels }} |
0 commit comments