|
| 1 | +name: CI |
| 2 | + |
| 3 | +on: [push] |
| 4 | + |
| 5 | +jobs: |
| 6 | + build: |
| 7 | + runs-on: ubuntu-latest |
| 8 | + if: "!contains(github.event.head_commit.message, '[skip ci]')" |
| 9 | + strategy: |
| 10 | + matrix: |
| 11 | + image-name: [base, base-2] |
| 12 | + gdal-version: [2.4, 3.1] |
| 13 | + steps: |
| 14 | + - uses: actions/checkout@v2 |
| 15 | + - name: Set up Python |
| 16 | + uses: actions/setup-python@v1 |
| 17 | + with: |
| 18 | + python-version: "3.x" |
| 19 | + - name: Install dependencies |
| 20 | + run: | |
| 21 | + python -m pip install --upgrade pip |
| 22 | + python -m pip install boto3 click |
| 23 | + - name: Login to DockerHub |
| 24 | + uses: docker/login-action@v1 |
| 25 | + with: |
| 26 | + username: ${{ secrets.DOCKERHUB_USERNAME }} |
| 27 | + password: ${{ secrets.DOCKERHUB_TOKEN }} |
| 28 | + |
| 29 | + - name: Common build cache |
| 30 | + uses: actions/cache@v2 |
| 31 | + id: common-cache |
| 32 | + with: |
| 33 | + path: /tmp/docker |
| 34 | + key: ${{ matrix.image-name }}-${{ hashFiles(format('common/{0}/Dockerfile', matrix.image-name)) }} |
| 35 | + |
| 36 | + - name: create base image |
| 37 | + if: steps.common-cache.outputs.cache-hit != 'true' |
| 38 | + run: | |
| 39 | + docker build -f common/${{ matrix.image-name }}/Dockerfile -t ${{ matrix.image-name }}:build . |
| 40 | + mkdir -p /tmp/docker |
| 41 | + docker image save -o /tmp/docker/${{ matrix.image-name }}.tar ${{ matrix.image-name }}:build |
| 42 | +
|
| 43 | + - name: Restore base image |
| 44 | + if: steps.common-cache.outputs.cache-hit == 'true' |
| 45 | + run: | |
| 46 | + docker image load -i /tmp/docker/${{ matrix.image-name }}.tar |
| 47 | + docker images |
| 48 | +
|
| 49 | + - name: GDAL build Cache |
| 50 | + uses: actions/cache@v2 |
| 51 | + id: gdal-cache |
| 52 | + with: |
| 53 | + path: /tmp/docker |
| 54 | + key: gdal${{ matrix.gdal-version }}-${{ hashFiles(format('gdal{0}/Dockerfile', matrix.gdal-version)) }}-${{ hashFiles(format('common/{0}/Dockerfile', matrix.image-name)) }} |
| 55 | + |
| 56 | + - name: create gdal docker image |
| 57 | + if: steps.gdal-cache.outputs.cache-hit != 'true' |
| 58 | + run: | |
| 59 | + docker build \ |
| 60 | + --build-arg IMAGE_VERSION=${{ matrix.image-name }} \ |
| 61 | + -f gdal${{ matrix.gdal-version }}/Dockerfile \ |
| 62 | + -t lambgeo/lambda-${{ matrix.image-name }}:gdal${{ matrix.gdal-version }} . |
| 63 | + mkdir -p /tmp/docker |
| 64 | + docker image save \ |
| 65 | + -o /tmp/docker/lambda-${{ matrix.image-name }}-gdal${{ matrix.gdal-version }}.tar \ |
| 66 | + lambgeo/lambda-${{ matrix.image-name }}:gdal${{ matrix.gdal-version }} |
| 67 | +
|
| 68 | + - name: Restore dependencies |
| 69 | + if: steps.gdal-cache.outputs.cache-hit == 'true' |
| 70 | + run: | |
| 71 | + docker image load -i /tmp/docker/lambda-${{ matrix.image-name }}-gdal${{ matrix.gdal-version }}.tar |
| 72 | + docker images |
| 73 | +
|
| 74 | + - name: Run Tests |
| 75 | + run: | |
| 76 | + docker run \ |
| 77 | + -v ${{ github.workspace }}:/local --rm \ |
| 78 | + lambgeo/lambda-${{ matrix.image-name }}:gdal${{ matrix.gdal-version }} \ |
| 79 | + sh -c "cd /local/tests && sh tests.sh" |
| 80 | +
|
| 81 | + - name: Push to DockerHub |
| 82 | + if: contains(github.ref, 'tags') |
| 83 | + run: docker push lambgeo/lambda-${{ matrix.image-name }}:gdal${{ matrix.gdal-version }} |
| 84 | + |
| 85 | + - name: Create and Publish Layer |
| 86 | + if: contains(github.ref, 'tags') |
| 87 | + run: | |
| 88 | + docker run \ |
| 89 | + -v ${{ github.workspace }}:/local --rm \ |
| 90 | + lambgeo/lambda-${{ matrix.image-name }}:gdal${{ matrix.gdal-version }} \ |
| 91 | + sh -c "cd /local/scripts && sh create-lambda-layer.sh" |
| 92 | +
|
| 93 | + python scripts/deploy-layer.py package.zip ${{ matrix.gdal-version }} ${{ matrix.image-version }} |
| 94 | +
|
| 95 | + runtimes: |
| 96 | + needs: [build] |
| 97 | + runs-on: ubuntu-latest |
| 98 | + if: contains(github.ref, 'tags') |
| 99 | + strategy: |
| 100 | + matrix: |
| 101 | + runtimes: [py3.7, py3.8] |
| 102 | + steps: |
| 103 | + - uses: actions/checkout@v2 |
| 104 | + - name: Login to DockerHub |
| 105 | + uses: docker/login-action@v1 |
| 106 | + with: |
| 107 | + username: ${{ secrets.DOCKERHUB_USERNAME }} |
| 108 | + password: ${{ secrets.DOCKERHUB_TOKEN }} |
| 109 | + |
| 110 | + - name: Push to DockerHub |
| 111 | + env: |
| 112 | + GDAL_VERSIONS: "2.4 3.1" |
| 113 | + run: | |
| 114 | + for GDAL_VERSION in ${GDAL_VERSIONS}; do |
| 115 | + docker build \ |
| 116 | + --build-arg GDAL_VERSION=${GDAL_VERSION} \ |
| 117 | + -f runtimes/${{ matrix.runtimes }} \ |
| 118 | + -t lambgeo/lambda:gdal${GDAL_VERSION}-${{ matrix.runtimes }} . |
| 119 | + docker push lambgeo/lambda:gdal${GDAL_VERSION}-${{ matrix.runtimes }} |
| 120 | + done |
0 commit comments