|
| 1 | +on: |
| 2 | + workflow_call: |
| 3 | + inputs: |
| 4 | + test: |
| 5 | + required: false |
| 6 | + type: boolean |
| 7 | +jobs: |
| 8 | + images: |
| 9 | + runs-on: ubuntu-latest |
| 10 | + strategy: |
| 11 | + matrix: |
| 12 | + dvc: [1, 2] |
| 13 | + base: [0, 1] |
| 14 | + gpu: [false, true] |
| 15 | + include: |
| 16 | + - base: 0 |
| 17 | + ubuntu: 18.04 |
| 18 | + python: 2.7 |
| 19 | + cuda: 10.1 |
| 20 | + cudnn: 7 |
| 21 | + - base: 1 |
| 22 | + ubuntu: 20.04 |
| 23 | + python: 3.8 |
| 24 | + cuda: 11.2.1 |
| 25 | + cudnn: 8 |
| 26 | + - latest: true # update the values below after introducing a new major version |
| 27 | + base: 1 |
| 28 | + dvc: 2 |
| 29 | + steps: |
| 30 | + - uses: actions/checkout@v2 |
| 31 | + with: |
| 32 | + ref: ${{ github.event.pull_request.head.sha || github.ref }} |
| 33 | + fetch-depth: 0 |
| 34 | + - name: Metadata |
| 35 | + id: metadata |
| 36 | + run: | |
| 37 | + latest_tag=$(git describe --tags | cut -d- -f1) |
| 38 | + cml_version=${latest_tag##v} |
| 39 | + dvc_version=$(python3 -c ' |
| 40 | + from distutils.version import StrictVersion as Ver |
| 41 | + from urllib.request import urlopen |
| 42 | + from json import load |
| 43 | + data = load(urlopen("https://pypi.org/pypi/dvc/json")) |
| 44 | + ver_pre = "${{ matrix.dvc }}".rstrip(".") + "." |
| 45 | + print( |
| 46 | + max( |
| 47 | + (i.strip() for i in data["releases"] if i.startswith(ver_pre)), |
| 48 | + default="${{ matrix.dvc }}", |
| 49 | + key=Ver |
| 50 | + ) |
| 51 | + )') |
| 52 | + echo ::set-output name=cache_tag::${cml_version}-${dvc_version}-${{ matrix.base }}-${{ matrix.gpu }} |
| 53 | + echo ::set-output name=cml_version::$cml_version |
| 54 | + tag=${cml_version//.*/}-dvc${{ matrix.dvc }}-base${{ matrix.base }} |
| 55 | + if [[ ${{ matrix.gpu }} == true ]]; then |
| 56 | + echo ::set-output name=base::nvidia/cuda:${{ matrix.cuda }}-cudnn${{ matrix.cudnn }}-runtime-ubuntu${{ matrix.ubuntu }} |
| 57 | + tag=${tag}-gpu |
| 58 | + else |
| 59 | + echo ::set-output name=base::ubuntu:${{ matrix.ubuntu }} |
| 60 | + fi |
| 61 | +
|
| 62 | + TAGS="$( |
| 63 | + for registry in docker.io/{dvcorg,iterativeai} ghcr.io/iterative; do |
| 64 | + if [[ "${{ matrix.latest }}" == "true" ]]; then |
| 65 | + if [[ "${{ matrix.gpu }}" == "true" ]]; then |
| 66 | + echo "${registry}/cml:latest-gpu" |
| 67 | + else |
| 68 | + echo "${registry}/cml:latest" |
| 69 | + fi |
| 70 | + fi |
| 71 | + echo "${registry}/cml:${tag}" |
| 72 | + done | head -c-1 |
| 73 | + )" |
| 74 | + echo ::set-output name=tags::"${TAGS//$'\n'/'%0A'}" |
| 75 | + - uses: docker/setup-buildx-action@v1 |
| 76 | + - uses: actions/cache@v2 |
| 77 | + with: |
| 78 | + path: /tmp/.buildx-cache |
| 79 | + key: |
| 80 | + ${{ runner.os }}-buildx-${{ steps.metadata.outputs.cache_tag }}-${{ |
| 81 | + github.sha }} |
| 82 | + restore-keys: |
| 83 | + ${{ runner.os }}-buildx-${{ steps.metadata.outputs.cache_tag }}- |
| 84 | + - uses: docker/login-action@v1 |
| 85 | + with: |
| 86 | + registry: docker.io |
| 87 | + username: ${{ secrets.DOCKERHUB_USERNAME }} |
| 88 | + password: ${{ secrets.DOCKERHUB_PASSWORD }} |
| 89 | + - uses: docker/login-action@v1 |
| 90 | + with: |
| 91 | + registry: ghcr.io |
| 92 | + username: ${{ github.repository_owner }} |
| 93 | + password: ${{ github.token }} |
| 94 | + - uses: docker/build-push-action@v2 |
| 95 | + with: |
| 96 | + push: |
| 97 | + ${{ github.event_name == 'push' || github.event_name == 'schedule' |
| 98 | + || github.event_name == 'workflow_dispatch' }} |
| 99 | + context: ./ |
| 100 | + file: ./Dockerfile |
| 101 | + tags: | |
| 102 | + ${{ steps.metadata.outputs.tags }} |
| 103 | + build-args: | |
| 104 | + CML_VERSION=${{ steps.metadata.outputs.cml_version }} |
| 105 | + DVC_VERSION=${{ matrix.dvc }} |
| 106 | + PYTHON_VERSION=${{ matrix.python }} |
| 107 | + BASE_IMAGE=${{ steps.metadata.outputs.base }} |
| 108 | + pull: true |
| 109 | + cache-from: type=local,src=/tmp/.buildx-cache |
| 110 | + cache-to: type=local,dest=/tmp/.buildx-cache-new |
| 111 | + - name: Move cache |
| 112 | + # https://github.com/docker/build-push-action/issues/252 |
| 113 | + # https://github.com/moby/buildkit/issues/1896 |
| 114 | + run: | |
| 115 | + rm -rf /tmp/.buildx-cache |
| 116 | + mv /tmp/.buildx-cache-new /tmp/.buildx-cache |
0 commit comments