diff --git a/.github/workflows/build_images.yml b/.github/workflows/build_images.yml new file mode 100644 index 0000000..c25064f --- /dev/null +++ b/.github/workflows/build_images.yml @@ -0,0 +1,116 @@ +--- +name: "Build Docker images" +on: + push: + branches: ['**'] + release: + types: [released] +env: + IMAGE_NAME: "${{ secrets.DOCKER_ORG }}/nansat_base" +jobs: + build_standard_docker_image: + runs-on: 'ubuntu-20.04' + steps: + - name: 'Checkout repository' + uses: actions/checkout@v2 + + - name: "Extract tag name" + id: get_version + run: | + if [[ $GITHUB_REF == refs/tags/* ]];then + TAG="${GITHUB_REF#refs/tags/}" + else + TAG='tmp' + fi + echo "::set-output name=VERSION::${TAG}" + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v1 + + - name: Cache Docker layers + uses: actions/cache@v2 + with: + path: /tmp/.buildx-cache + key: ${{ runner.os }}-buildx-standard-${{ github.sha }} + restore-keys: | + ${{ runner.os }}-buildx-standard- + + - name: Login to DockerHub + uses: docker/login-action@v1 + with: + username: ${{ secrets.DOCKER_USER }} + password: ${{ secrets.DOCKER_PASS }} + + - name: Build docker image + uses: docker/build-push-action@v2 + with: + context: . + file: Dockerfile + push: ${{ startsWith(github.ref, 'refs/tags/') }} + tags: | + ${{ env.IMAGE_NAME }}:latest + ${{ env.IMAGE_NAME }}:${{ steps.get_version.outputs.VERSION }} + cache-from: type=local,src=/tmp/.buildx-cache + cache-to: type=local,dest=/tmp/.buildx-cache-new + + # Temp fix + # https://github.com/docker/build-push-action/issues/252 + # https://github.com/moby/buildkit/issues/1896 + - name: Move cache + run: | + rm -rf /tmp/.buildx-cache + mv /tmp/.buildx-cache-new /tmp/.buildx-cache + + build_slim_docker_image: + runs-on: 'ubuntu-20.04' + steps: + - name: 'Checkout repository' + uses: actions/checkout@v2 + + - name: "Extract tag name" + id: get_version + run: | + if [[ $GITHUB_REF == refs/tags/* ]];then + TAG="${GITHUB_REF#refs/tags/}" + else + TAG='tmp' + fi + echo "::set-output name=VERSION::${TAG}" + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v1 + + - name: Cache Docker layers + uses: actions/cache@v2 + with: + path: /tmp/.buildx-cache + key: ${{ runner.os }}-buildx-slim-${{ github.sha }} + restore-keys: | + ${{ runner.os }}-buildx-slim- + + - name: Login to DockerHub + uses: docker/login-action@v1 + with: + username: ${{ secrets.DOCKER_USER }} + password: ${{ secrets.DOCKER_PASS }} + + - name: Build docker image + uses: docker/build-push-action@v2 + with: + context: . + file: Dockerfile_slim + push: ${{ startsWith(github.ref, 'refs/tags/') }} + tags: | + ${{ env.IMAGE_NAME }}:latest-slim + ${{ env.IMAGE_NAME }}:${{ steps.get_version.outputs.VERSION }}-slim + cache-from: type=local,src=/tmp/.buildx-cache + cache-to: type=local,dest=/tmp/.buildx-cache-new + + # Temp fix + # https://github.com/docker/build-push-action/issues/252 + # https://github.com/moby/buildkit/issues/1896 + - name: Move cache + run: | + rm -rf /tmp/.buildx-cache + mv /tmp/.buildx-cache-new /tmp/.buildx-cache +... \ No newline at end of file diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 3099ada..0000000 --- a/.travis.yml +++ /dev/null @@ -1,65 +0,0 @@ ---- -language: shell -services: - - docker - -# Environment variables defined as part of the Travis CI repository configuration are: -# - DOCKER_ORG: the docker hub organization (or user) to which the image will be pushed -# - DOCKER_USER: the docker hub user used to log in to the docker hub -# - DOCKER_PASS: the password of this user - -env: - global: - - IMAGE_NAME="${DOCKER_ORG}/nansat_base" - - DOCKER_TMP_TAG='tmp' - -jobs: - include: - - stage: 'Build Docker images' - name: 'Build standard image' - install: - - docker pull "${IMAGE_NAME}" || true - script: - - > - docker build . - --cache-from "${IMAGE_NAME}" - -t "${IMAGE_NAME}:${DOCKER_TMP_TAG}" - # Basic test - - docker run --rm "${IMAGE_NAME}:${DOCKER_TMP_TAG}" python -c 'import gdal' - before_deploy: - - docker login -u "${DOCKER_USER}" -p "${DOCKER_PASS}" - deploy: - provider: script - on: - tags: true - script: /bin/bash docker_push.sh "${IMAGE_NAME}" '' - - - name: 'Build slim image' - env: - - COMPILE_STAGE_SUFFIX='-compile-stage' - - SLIM_SUFFIX='-slim' - install: - - docker pull "${IMAGE_NAME}:latest${COMPILE_STAGE_SUFFIX}" || true - - docker pull "${IMAGE_NAME}:latest${SLIM_SUFFIX}" || true - script: - - > - docker build . - -f Dockerfile_slim --target builder - --cache-from "${IMAGE_NAME}:latest${COMPILE_STAGE_SUFFIX}" - -t "${IMAGE_NAME}:${DOCKER_TMP_TAG}${COMPILE_STAGE_SUFFIX}" - - > - docker build . - -f Dockerfile_slim - --cache-from "${IMAGE_NAME}:${DOCKER_TMP_TAG}${COMPILE_STAGE_SUFFIX}" - --cache-from "${IMAGE_NAME}:latest${SLIM_SUFFIX}" - -t "${IMAGE_NAME}:${DOCKER_TMP_TAG}${SLIM_SUFFIX}" - # Basic test - - docker run --rm "${IMAGE_NAME}:${DOCKER_TMP_TAG}${SLIM_SUFFIX}" python -c 'import gdal' - before_deploy: - - docker login -u "${DOCKER_USER}" -p "${DOCKER_PASS}" - deploy: - provider: script - on: - tags: true - script: /bin/bash docker_push.sh "${IMAGE_NAME}" "${COMPILE_STAGE_SUFFIX}" "${SLIM_SUFFIX}" -... \ No newline at end of file diff --git a/docker_push.sh b/docker_push.sh deleted file mode 100644 index 921297f..0000000 --- a/docker_push.sh +++ /dev/null @@ -1,12 +0,0 @@ -#!/bin/bash -image_name="$1" -shift - -for suffix in "$@";do - for tag in "${TRAVIS_TAG}${suffix}" "latest${suffix}";do - echo "Tag ${image_name}:${DOCKER_TMP_TAG}${suffix} as ${image_name}:${tag}" - docker tag "${image_name}:${DOCKER_TMP_TAG}${suffix}" "${image_name}:${tag}" - echo "Push ${image_name}:${tag}" - docker push "${image_name}:${tag}" - done -done