|
| 1 | +# Licensed to the Apache Software Foundation (ASF) under one or more |
| 2 | +# contributor license agreements. See the NOTICE file distributed with |
| 3 | +# this work for additional information regarding copyright ownership. |
| 4 | +# The ASF licenses this file to You under the Apache License, Version 2.0 |
| 5 | +# (the "License"); you may not use this file except in compliance with |
| 6 | +# the License. You may obtain a copy of the License at |
| 7 | +# |
| 8 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +# |
| 10 | +# Unless required by applicable law or agreed to in writing, software |
| 11 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | +# See the License for the specific language governing permissions and |
| 14 | +# limitations under the License. |
| 15 | + |
| 16 | +name: build-and-tag-ranger-image |
| 17 | + |
| 18 | +# This workflow builds the following images: ranger, ranger-db, ranger-solr, ranger-zk. |
| 19 | +# It also pushes the image to the GitHub Container Registry, tagging it based on the ranger version present in the release branch. |
| 20 | +# It pushes the images to DockerHub if an OAuth token is provided as input. |
| 21 | + |
| 22 | +# Use this command to generate a unique 11 character token: |
| 23 | +# code=$(uuidgen | tr A-Z a-z | cut -c 1-11) |
| 24 | +# then pass the code to state param here: http://oauth.apache.org/auth?redirect_uri=https://github.com&state=code |
| 25 | +# On successful authentication, it generates an OAuth token on redirect_uri that can be used to trigger the workflow and push the images to DockerHub. |
| 26 | + |
| 27 | +# For more info, read ASF OAuth doc here: https://idm.apache.org/api.html |
| 28 | +on: |
| 29 | + workflow_dispatch: |
| 30 | + inputs: |
| 31 | + token: |
| 32 | + description: 'OAuth Access Token' |
| 33 | + required: true |
| 34 | + type: string |
| 35 | + push: |
| 36 | + branches: |
| 37 | + - 'ranger-**' |
| 38 | + |
| 39 | +permissions: |
| 40 | + contents: read |
| 41 | + packages: write |
| 42 | + |
| 43 | +jobs: |
| 44 | + build: |
| 45 | + runs-on: ubuntu-latest |
| 46 | + steps: |
| 47 | + - uses: actions/checkout@v4 |
| 48 | + |
| 49 | + - name: Download build-8 artifacts |
| 50 | + uses: dawidd6/action-download-artifact@v11 |
| 51 | + with: |
| 52 | + name: target-8 |
| 53 | + workflow: ci.yml |
| 54 | + |
| 55 | + - name: Copy artifacts for docker build |
| 56 | + run: | |
| 57 | + cp ranger-*-admin.tar.gz dev-support/ranger-docker/dist |
| 58 | + cp version dev-support/ranger-docker/dist |
| 59 | +
|
| 60 | + - name: Run download-archives.sh |
| 61 | + run: | |
| 62 | + cd dev-support/ranger-docker |
| 63 | + ./download-archives.sh none |
| 64 | +
|
| 65 | + - name: Generate image ID |
| 66 | + id: meta |
| 67 | + uses: docker/metadata-action@8e5442c4ef9f78752691e2d8f8d19755c6f78e81 |
| 68 | + with: |
| 69 | + images: | |
| 70 | + ghcr.io/${{ github.repository_owner }}/ranger |
| 71 | + tags: | |
| 72 | + type=match,pattern=ranger-(.*),value={{branch}},group=1 |
| 73 | + flavor: | |
| 74 | + latest=false |
| 75 | +
|
| 76 | + - name: Set up QEMU |
| 77 | + uses: docker/setup-qemu-action@49b3bc8e6bdd4a60e6116a5414239cba5943d3cf |
| 78 | + |
| 79 | + - name: Set up Docker Buildx |
| 80 | + uses: docker/setup-buildx-action@c47758b77c9736f4b2ef4073d4d51994fabfe349 |
| 81 | + |
| 82 | + - name: Login to GitHub Container Registry |
| 83 | + id: login |
| 84 | + uses: docker/login-action@9780b0c442fbb1117ed29e0efdff1e18412f7567 |
| 85 | + with: |
| 86 | + registry: ghcr.io |
| 87 | + username: ${{ github.repository_owner }} |
| 88 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 89 | + |
| 90 | + - name: Build and push images |
| 91 | + id: build |
| 92 | + working-directory: dev-support/ranger-docker |
| 93 | + run: | |
| 94 | + set -o allexport |
| 95 | + source .env |
| 96 | + set +o allexport |
| 97 | + docker buildx build \ |
| 98 | + --build-arg RANGER_BASE_IMAGE=${RANGER_BASE_IMAGE} \ |
| 99 | + --build-arg RANGER_BASE_VERSION=${RANGER_BASE_VERSION} \ |
| 100 | + --build-arg RANGER_VERSION=${RANGER_VERSION} \ |
| 101 | + --build-arg RANGER_DB_TYPE=postgres \ |
| 102 | + --file Dockerfile.ranger \ |
| 103 | + --platform linux/amd64,linux/arm64 \ |
| 104 | + --tag ghcr.io/${{ github.repository_owner }}/ranger:${RANGER_VERSION} \ |
| 105 | + --push . |
| 106 | + docker buildx build \ |
| 107 | + --build-arg POSTGRES_VERSION=${POSTGRES_VERSION} \ |
| 108 | + --file Dockerfile.ranger-postgres \ |
| 109 | + --platform linux/amd64,linux/arm64 \ |
| 110 | + --tag ghcr.io/${{ github.repository_owner }}/ranger-db:${RANGER_VERSION} \ |
| 111 | + --push . |
| 112 | + docker buildx build \ |
| 113 | + --build-arg SOLR_VERSION=${SOLR_VERSION} \ |
| 114 | + --file Dockerfile.ranger-solr \ |
| 115 | + --platform linux/amd64,linux/arm64 \ |
| 116 | + --tag ghcr.io/${{ github.repository_owner }}/ranger-solr:${RANGER_VERSION} \ |
| 117 | + --push . |
| 118 | + docker buildx build \ |
| 119 | + --build-arg ZK_VERSION=${ZK_VERSION} \ |
| 120 | + --file Dockerfile.ranger-zk \ |
| 121 | + --platform linux/amd64,linux/arm64 \ |
| 122 | + --tag ghcr.io/${{ github.repository_owner }}/ranger-zk:${RANGER_VERSION} \ |
| 123 | + --push . |
| 124 | +
|
| 125 | + tag: |
| 126 | + needs: build |
| 127 | + if: ${{ github.event.inputs.token != '' }} |
| 128 | + runs-on: ubuntu-latest |
| 129 | + env: |
| 130 | + DOCKERHUB_USER: ${{ secrets.DOCKERHUB_USER }} |
| 131 | + IMAGE_ID: ${{ needs.build.outputs.image-id }} |
| 132 | + REGISTRIES: ghcr.io # docker.io is appended dynamically |
| 133 | + steps: |
| 134 | + - name: Verify OAuth Token |
| 135 | + run: | |
| 136 | + response=$(curl https://oauth.apache.org/token\?code\=${{ github.event.inputs.token }}) |
| 137 | + echo "$response" | jq -e . >/dev/null 2>&1 |
| 138 | + if [[ $? -eq 0 ]]; then |
| 139 | + check=$(echo $response | jq -e --arg str "ranger" '.pmcs | index($str) != null') |
| 140 | + if [[ $check == true ]]; then |
| 141 | + echo "Authorized to push to Docker Hub" |
| 142 | + else |
| 143 | + echo "Not authorized to push to Docker Hub" |
| 144 | + exit 1 |
| 145 | + fi |
| 146 | + else |
| 147 | + echo $response |
| 148 | + fi |
| 149 | + - name: Generate tags |
| 150 | + uses: docker/metadata-action@8e5442c4ef9f78752691e2d8f8d19755c6f78e81 |
| 151 | + with: |
| 152 | + images: | |
| 153 | + ${{ github.repository_owner }}/ranger |
| 154 | + tags: | |
| 155 | + type=match,pattern=release-docker-(.*),value={{ ref_name }},group=1 |
| 156 | + flavor: | |
| 157 | + latest=false |
| 158 | +
|
| 159 | + - name: Add Docker Hub to targets |
| 160 | + if: ${{ env.DOCKERHUB_USER }} |
| 161 | + run: | |
| 162 | + echo "REGISTRIES=${{ env.REGISTRIES }} docker.io" >> $GITHUB_ENV |
| 163 | +
|
| 164 | + - name: Pull image |
| 165 | + run: | |
| 166 | + docker pull "$IMAGE_ID" |
| 167 | +
|
| 168 | + - name: Login to GitHub Container Registry |
| 169 | + uses: docker/login-action@9780b0c442fbb1117ed29e0efdff1e18412f7567 |
| 170 | + with: |
| 171 | + registry: ghcr.io |
| 172 | + username: ${{ github.repository_owner }} |
| 173 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 174 | + |
| 175 | + - name: Login to Docker Hub |
| 176 | + if: ${{ env.DOCKERHUB_USER }} |
| 177 | + uses: docker/login-action@9780b0c442fbb1117ed29e0efdff1e18412f7567 |
| 178 | + with: |
| 179 | + username: ${{ env.DOCKERHUB_USER }} |
| 180 | + password: ${{ secrets.DOCKERHUB_TOKEN }} |
| 181 | + |
| 182 | + - name: Apply tags to existing image |
| 183 | + run: | |
| 184 | + set -x |
| 185 | + for registry in $REGISTRIES; do |
| 186 | + opts="$(echo "$DOCKER_METADATA_OUTPUT_TAGS" | sed "s@^@--tag $registry/@g" | xargs echo)" |
| 187 | + if [[ -n "$opts" ]]; then |
| 188 | + docker buildx imagetools create $opts "$IMAGE_ID" |
| 189 | + fi |
| 190 | + done |
0 commit comments