|
| 1 | +name: Publish Docker image |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + push: |
| 6 | + branches: [ main ] |
| 7 | + paths: |
| 8 | + - 'Dockerfile' |
| 9 | + - '.github/workflows/publish-docker.yml' |
| 10 | + schedule: |
| 11 | + # Monday at 3:00 AM UTC |
| 12 | + - cron: '0 3 * * 1' |
| 13 | + |
| 14 | +jobs: |
| 15 | + build-and-publish-latest: |
| 16 | + runs-on: ubuntu-latest |
| 17 | + steps: |
| 18 | + - uses: actions/checkout@v3 |
| 19 | + - name: Set up Docker Buildx |
| 20 | + id: buildx |
| 21 | + uses: docker/setup-buildx-action@v2 |
| 22 | + |
| 23 | + - name: Login to the GitHub Container Registry |
| 24 | + uses: docker/login-action@v2 |
| 25 | + with: |
| 26 | + registry: ghcr.io |
| 27 | + username: ${{github.actor}} |
| 28 | + password: ${{secrets.GITHUB_TOKEN}} |
| 29 | + |
| 30 | + - name: Generate image ID and version |
| 31 | + run: | |
| 32 | + IMAGE_ID=ghcr.io/${{ github.repository_owner }}/dsri-nvidia-driver |
| 33 | + # Change all uppercase to lowercase |
| 34 | + IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]') |
| 35 | + # Strip git ref prefix from version |
| 36 | + VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,') |
| 37 | + # Strip "v" prefix from tag name |
| 38 | + [[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION=$(echo $VERSION | sed -e 's/^v//') |
| 39 | + # Use Docker `latest` tag convention |
| 40 | + [ "$VERSION" == "main" ] && VERSION=latest-scos4.17 |
| 41 | + echo "IMAGE_ID=$IMAGE_ID" >> $GITHUB_ENV |
| 42 | + echo "VERSION=$VERSION" >> $GITHUB_ENV |
| 43 | +
|
| 44 | + # Cache: https://docs.docker.com/build/ci/github-actions/cache/#github-cache |
| 45 | + - name: Build and publish main latest Docker image |
| 46 | + uses: docker/build-push-action@v4 |
| 47 | + with: |
| 48 | + context: ./ |
| 49 | + file: ./Dockerfile |
| 50 | + pull: true |
| 51 | + push: true |
| 52 | + tags: ${{ env.IMAGE_ID }}:${{ env.VERSION }} |
| 53 | + cache-from: type=gha |
| 54 | + cache-to: type=gha,mode=max |
0 commit comments