|
| 1 | +name: Build Docker Container |
| 2 | +on: |
| 3 | + pull_request: |
| 4 | + types: [opened, synchronize, reopened] |
| 5 | + branches: |
| 6 | + - main |
| 7 | + - 'release/[0-9]+.[0-9]+' |
| 8 | + push: |
| 9 | + branches: |
| 10 | + - 'main' |
| 11 | + release: |
| 12 | + types: [created, published] |
| 13 | + schedule: |
| 14 | + - cron: '0 2 * * *' |
| 15 | + |
| 16 | +# TODO: docker containers created through a release cut vs PR to the release branch |
| 17 | +# will be pushed to different locations (i.e one will be sparseml the other will be test-sparseml). |
| 18 | +# These containers rely on the new internal pypi server being enabled. Once enabled, |
| 19 | +# this workflow can be expanded to make this distinction. |
| 20 | +env: |
| 21 | + RELEASE: ${{ github.event_name =='release' || (startsWith(github.base_ref, 'release/') && github.event_name == 'pull_request')}} |
| 22 | + DEV: ${{ github.base_ref == 'main' && github.event_name == 'pull_request'}} |
| 23 | + NAME: ${{ github.event.number }} |
| 24 | + |
| 25 | +permissions: |
| 26 | + contents: read |
| 27 | + packages: write |
| 28 | + |
| 29 | +jobs: |
| 30 | + build-container: |
| 31 | + name: Build sparseml container |
| 32 | + runs-on: ubuntu-20.04 |
| 33 | + steps: |
| 34 | + - name: Checkout code |
| 35 | + uses: actions/checkout@v3 |
| 36 | + with: |
| 37 | + fetch-depth: 1 |
| 38 | + - name: Set up Docker Buildx |
| 39 | + id: buildx |
| 40 | + uses: docker/setup-buildx-action@v2 |
| 41 | + with: |
| 42 | + buildkitd-flags: --debug |
| 43 | + - name: Get current date |
| 44 | + id: date |
| 45 | + run: echo "::set-output name=date::$(date +'%Y%m%d')" |
| 46 | + - name: Get the current version |
| 47 | + if: ${{ env.RELEASE == 'true' }} |
| 48 | + id: version |
| 49 | + run: echo "::set-output name=version::$(echo ${{ github.base_ref }} | cut -c 9-15)" |
| 50 | + - name: Login to Github Packages |
| 51 | + uses: docker/login-action@v2 |
| 52 | + with: |
| 53 | + registry: ghcr.io |
| 54 | + username: ${{ github.actor }} |
| 55 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 56 | + - name: Build Dev Docker Container |
| 57 | + if: ${{ env.DEV == 'true' }} |
| 58 | + uses: docker/build-push-action@v4 |
| 59 | + with: |
| 60 | + context: ./docker/containers/docker_dev |
| 61 | + build-args: | |
| 62 | + BRANCH=${{github.head_ref}} |
| 63 | + push: true |
| 64 | + tags: ghcr.io/neuralmagic/sparseml-dev:${{ env.NAME }} |
| 65 | + - name: Build Release Docker Container |
| 66 | + if: ${{ env.RELEASE == 'true' }} |
| 67 | + uses: docker/build-push-action@v4 |
| 68 | + with: |
| 69 | + context: ./docker/containers/docker_release |
| 70 | + build-args: | |
| 71 | + VERSION=${{ steps.version.outputs.version }} |
| 72 | + push: true |
| 73 | + tags: ghcr.io/neuralmagic/test-sparseml:latest, ghcr.io/neuralmagic/test-sparseml:${{ steps.version.outputs.version }} |
| 74 | + - name: Build Nightly Docker Container |
| 75 | + if: ${{ env.DEV == 'false' && env.RELEASE == 'false'}} |
| 76 | + uses: docker/build-push-action@v4 |
| 77 | + with: |
| 78 | + context: ./docker/containers/docker_nightly |
| 79 | + push: true |
| 80 | + tags: ghcr.io/neuralmagic/test-sparseml-nightly:latest, ghcr.io/neuralmagic/test-sparseml-nightly:${{ steps.date.outputs.date }} |
0 commit comments