|
| 1 | +name: Docker Images Debian |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - main |
| 7 | + tags: |
| 8 | + - v* |
| 9 | + pull_request: |
| 10 | + branches: |
| 11 | + - main |
| 12 | + schedule: |
| 13 | + - cron: '23 1 * * 0' |
| 14 | + release: |
| 15 | + types: [published] |
| 16 | + workflow_dispatch: |
| 17 | + |
| 18 | +jobs: |
| 19 | + docker: |
| 20 | + name: Build and publish Debian images |
| 21 | + runs-on: ubuntu-latest |
| 22 | + |
| 23 | + steps: |
| 24 | + - name: Checkout |
| 25 | + uses: actions/checkout@v2 |
| 26 | + with: |
| 27 | + fetch-depth: 0 |
| 28 | + - name: Prepare |
| 29 | + id: prep |
| 30 | + run: | |
| 31 | + DOCKER_IMAGE=madanalysis5/madanalysis5 |
| 32 | + VERSION=latest |
| 33 | + MADANALYSIS_VERISON=v1.10.0 |
| 34 | + REPO_NAME=${{github.repository}} |
| 35 | + REPO_NAME_LOWERCASE="${REPO_NAME,,}" |
| 36 | + if [[ $GITHUB_REF == refs/tags/* ]]; then |
| 37 | + VERSION=${GITHUB_REF#refs/tags/} |
| 38 | + elif [[ $GITHUB_REF == refs/pull/* ]]; then |
| 39 | + VERSION=pr-${{ github.event.number }} |
| 40 | + fi |
| 41 | + TAGS="${DOCKER_IMAGE}:${VERSION}" |
| 42 | + TAGS="$TAGS,${DOCKER_IMAGE}:latest,${DOCKER_IMAGE}:${MADANALYSIS_VERISON},${DOCKER_IMAGE}:sha-${GITHUB_SHA::8}" |
| 43 | + # Releases also have GITHUB_REFs that are tags, so reuse VERSION |
| 44 | + if [ "${{ github.event_name }}" = "release" ]; then |
| 45 | + TAGS="ghcr.io/${REPO_NAME_LOWERCASE}:latest,ghcr.io/${REPO_NAME_LOWERCASE}:latest-stable,ghcr.io/${REPO_NAME_LOWERCASE}:${MADANALYSIS_VERISON},ghcr.io/${REPO_NAME_LOWERCASE}:sha-${GITHUB_SHA::8}" |
| 46 | + fi |
| 47 | + echo ::set-output name=version::${VERSION} |
| 48 | + echo ::set-output name=tags::${TAGS} |
| 49 | + echo ::set-output name=created::$(date -u +'%Y-%m-%dT%H:%M:%SZ') |
| 50 | + echo ::set-output name=repo_name_lowercase::"${REPO_NAME_LOWERCASE}" |
| 51 | + echo ::set-output name=MADANALYSIS_VERISON::"${MADANALYSIS_VERISON}" |
| 52 | +
|
| 53 | + - name: Set up QEMU |
| 54 | + uses: docker/setup-qemu-action@v1 |
| 55 | + |
| 56 | + - name: Set up Docker Buildx |
| 57 | + uses: docker/setup-buildx-action@v1 |
| 58 | + |
| 59 | + # - name: Login to DockerHub |
| 60 | + # if: github.event_name != 'pull_request' |
| 61 | + # uses: docker/login-action@v1 |
| 62 | + # with: |
| 63 | + # username: ${{ secrets.DOCKERHUB_USERNAME }} |
| 64 | + # password: ${{ secrets.DOCKERHUB_TOKEN }} |
| 65 | + |
| 66 | + - name: Login to GitHub Container Registry |
| 67 | + if: github.event_name != 'pull_request' |
| 68 | + uses: docker/login-action@v1 |
| 69 | + with: |
| 70 | + registry: ghcr.io |
| 71 | + username: ${{ github.repository_owner }} |
| 72 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 73 | + |
| 74 | + - name: Test build |
| 75 | + id: docker_build_test |
| 76 | + uses: docker/build-push-action@v2 |
| 77 | + with: |
| 78 | + context: . |
| 79 | + file: docker/Dockerfile |
| 80 | + tags: ${{ steps.prep.outputs.tags }} |
| 81 | + labels: | |
| 82 | + org.opencontainers.image.source=${{ github.event.repository.html_url }} |
| 83 | + org.opencontainers.image.created=${{ steps.prep.outputs.created }} |
| 84 | + org.opencontainers.image.revision=${{ github.sha }} |
| 85 | + load: true |
| 86 | + push: false |
| 87 | + |
| 88 | + - name: Image digest |
| 89 | + run: echo ${{ steps.docker_build_test.outputs.digest }} |
| 90 | + |
| 91 | + - name: List built images |
| 92 | + run: docker images |
| 93 | + |
| 94 | + - name: List ma5 users settings |
| 95 | + run: >- |
| 96 | + docker run --rm |
| 97 | + madanalysis5/madanalysis5:sha-${GITHUB_SHA::8} |
| 98 | + 'cat $(find / -name "installation_options.dat")' |
| 99 | +
|
| 100 | + - name: Run test program |
| 101 | + run: >- |
| 102 | + docker run --rm |
| 103 | + -v $PWD:$PWD |
| 104 | + madanalysis5/madanalysis5:sha-${GITHUB_SHA::8} |
| 105 | + 'cat $(find /root/ -iname "differential_xsec_plot.ma5") | ma5 && tree differential_xsec_example' |
| 106 | +
|
| 107 | + - name: Build and publish to registry |
| 108 | + # every PR will trigger a push event on main, so check the push event is actually coming from main |
| 109 | + if: github.event_name == 'push' && github.ref == 'refs/heads/main' && github.repository == 'MadAnalysis/madanalysis5' |
| 110 | + id: docker_build_latest |
| 111 | + uses: docker/build-push-action@v2 |
| 112 | + with: |
| 113 | + context: . |
| 114 | + file: docker/Dockerfile |
| 115 | + tags: | |
| 116 | + ghcr.io/${{ steps.prep.outputs.repo_name_lowercase }}:latest |
| 117 | + labels: | |
| 118 | + org.opencontainers.image.source=${{ github.event.repository.html_url }} |
| 119 | + org.opencontainers.image.created=${{ steps.prep.outputs.created }} |
| 120 | + org.opencontainers.image.revision=${{ github.sha }} |
| 121 | + push: true |
| 122 | + |
| 123 | + - name: Build and publish to registry with release tag |
| 124 | + if: github.event_name == 'release' && github.event.action == 'published' && github.repository == 'MadAnalysis/madanalysis5' |
| 125 | + id: docker_build_release |
| 126 | + uses: docker/build-push-action@v2 |
| 127 | + with: |
| 128 | + context: . |
| 129 | + file: docker/Dockerfile |
| 130 | + tags: | |
| 131 | + ghcr.io/${{ steps.prep.outputs.repo_name_lowercase }}:latest |
| 132 | + ghcr.io/${{ steps.prep.outputs.repo_name_lowercase }}:latest-stable |
| 133 | + ghcr.io/${{ steps.prep.outputs.repo_name_lowercase }}:${{ steps.prep.outputs.MADANALYSIS_VERISON }} |
| 134 | + ghcr.io/${{ steps.prep.outputs.repo_name_lowercase }}:sha-${GITHUB_SHA::8} |
| 135 | + labels: | |
| 136 | + org.opencontainers.image.source=${{ github.event.repository.html_url }} |
| 137 | + org.opencontainers.image.created=${{ steps.prep.outputs.created }} |
| 138 | + org.opencontainers.image.revision=${{ github.sha }} |
| 139 | + push: true |
0 commit comments