|
| 1 | +name: Build Docker images and push to DockerHub |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + # Allow to run manually |
| 6 | + branches: |
| 7 | + - 'develop' |
| 8 | + - 'docker_hub_gha' |
| 9 | + push: |
| 10 | + tags: |
| 11 | + # Just create image on pushing a tag |
| 12 | + - '*' |
| 13 | + |
| 14 | +jobs: |
| 15 | + sagemath-dev: |
| 16 | + name: Build Docker image on target make-build and push to DockerHub sagemath-dev |
| 17 | + runs-on: ubuntu-latest |
| 18 | + steps: |
| 19 | + - name: Checkout |
| 20 | + uses: actions/checkout@v3 |
| 21 | + |
| 22 | + - name: Set tag |
| 23 | + # docker/metadata-action@v4 is not used since we need to distinguish |
| 24 | + # between latest and develop tags |
| 25 | + id: set_tag |
| 26 | + run: | |
| 27 | + git fetch --depth=1 origin +refs/tags/*:refs/tags/* |
| 28 | + TAG_NAME=$(git tag --sort=v:refname | tail -1) |
| 29 | + TAG="sagemath/sagemath-dev:$TAG_NAME" |
| 30 | + TAG_LIST="$TAG, sagemath/sagemath-dev:develop" |
| 31 | + TAG_LIST="$TAG" # don't tag develop until meaning of sagemath-dev is clear |
| 32 | + echo "TAG_NAME=$TAG_NAME" >> $GITHUB_ENV |
| 33 | + echo "TAG=$TAG" >> $GITHUB_ENV |
| 34 | + echo "TAG_LIST=$TAG_LIST" >> $GITHUB_ENV |
| 35 | +
|
| 36 | + - name: Update Tag List |
| 37 | + id: upd_tag_list |
| 38 | + run: | |
| 39 | + TAG_LIST="${{ env.TAG_LIST }}, sagemath/sagemath-dev:latest" |
| 40 | + TAG_LIST="${{ env.TAG_LIST }}" # don't tag latest until meaning of sagemath-dev is clear |
| 41 | + echo "TAG_LIST=$TAG_LIST" >> $GITHUB_ENV |
| 42 | + if: "!contains(env.TAG_NAME, 'beta') && !contains(env.TAG_NAME, 'rc')" |
| 43 | + |
| 44 | + - name: Check env |
| 45 | + run: | |
| 46 | + echo ${{ env.TAG_NAME }} |
| 47 | + echo ${{ env.TAG }} |
| 48 | + echo ${{ env.TAG_LIST }} |
| 49 | +
|
| 50 | + - name: Set up QEMU |
| 51 | + uses: docker/setup-qemu-action@v2 |
| 52 | + |
| 53 | + - name: Set up Docker Buildx |
| 54 | + uses: docker/setup-buildx-action@v2 |
| 55 | + |
| 56 | + - name: Login to Docker Hub |
| 57 | + uses: docker/login-action@v2 |
| 58 | + with: |
| 59 | + username: ${{ secrets.DOCKERHUB_USERNAME }} |
| 60 | + password: ${{ secrets.DOCKERHUB_TOKEN }} |
| 61 | + |
| 62 | + - name: Build and push make-build |
| 63 | + uses: docker/build-push-action@v4 |
| 64 | + with: |
| 65 | + context: . |
| 66 | + file: docker/Dockerfile |
| 67 | + target: make-build # see the corresponding header-note |
| 68 | + push: true |
| 69 | + tags: ${{ env.TAG_LIST }} |
| 70 | + cache-from: type=gha |
| 71 | + cache-to: type=gha,mode=max |
| 72 | + |
| 73 | + sagemath: |
| 74 | + needs: sagemath-dev |
| 75 | + name: Build Docker image on target sagemath and push to DockerHub sagemath |
| 76 | + runs-on: ubuntu-latest |
| 77 | + steps: |
| 78 | + - name: Checkout |
| 79 | + uses: actions/checkout@v3 |
| 80 | + |
| 81 | + - name: Set tag |
| 82 | + # docker/metadata-action@v4 is not used since we need to distinguish |
| 83 | + # between latest and develop tags |
| 84 | + id: set_tag |
| 85 | + run: | |
| 86 | + git fetch --depth=1 origin +refs/tags/*:refs/tags/* |
| 87 | + TAG_NAME=$(git tag --sort=v:refname | tail -1) |
| 88 | + TAG="sagemath/sagemath:$TAG_NAME" |
| 89 | + TAG_LIST="$TAG, sagemath/sagemath:develop" |
| 90 | + BASE="sagemath/sagemath-dev:$TAG_NAME" |
| 91 | + echo "TAG_NAME=$TAG_NAME" >> $GITHUB_ENV |
| 92 | + echo "TAG=$TAG" >> $GITHUB_ENV |
| 93 | + echo "TAG_LIST=$TAG_LIST" >> $GITHUB_ENV |
| 94 | + echo "BASE=$BASE" >> $GITHUB_ENV |
| 95 | +
|
| 96 | + - name: Update Tag List |
| 97 | + id: upd_tag_list |
| 98 | + run: | |
| 99 | + TAG_LIST="${{ env.TAG_LIST }}, sagemath/sagemath:latest" |
| 100 | + echo "TAG_LIST=$TAG_LIST" >> $GITHUB_ENV |
| 101 | + if: "!contains(env.TAG_NAME, 'beta') && !contains(env.TAG_NAME, 'rc')" |
| 102 | + |
| 103 | + - name: Set up QEMU |
| 104 | + uses: docker/setup-qemu-action@v2 |
| 105 | + |
| 106 | + - name: Set up Docker Buildx |
| 107 | + uses: docker/setup-buildx-action@v2 |
| 108 | + |
| 109 | + - name: Login to Docker Hub |
| 110 | + uses: docker/login-action@v2 |
| 111 | + with: |
| 112 | + username: ${{ secrets.DOCKERHUB_USERNAME }} |
| 113 | + password: ${{ secrets.DOCKERHUB_TOKEN }} |
| 114 | + |
| 115 | + - name: Build and push sagemath |
| 116 | + uses: docker/build-push-action@v4 |
| 117 | + with: |
| 118 | + context: . |
| 119 | + file: docker/Dockerfile |
| 120 | + build-args: | |
| 121 | + MAKE_BUILD=${{ env.BASE }} |
| 122 | + target: sagemath |
| 123 | + push: true |
| 124 | + tags: ${{ env.TAG_LIST }} |
| 125 | + cache-from: type=gha |
| 126 | + cache-to: type=gha,mode=max |
0 commit comments