|
| 1 | +name: Publish Build Artifacts |
| 2 | + |
| 3 | +on: push |
| 4 | + |
| 5 | +jobs: |
| 6 | + publish_images: |
| 7 | + # Optionally publish container images, guarded by the GitHub secret |
| 8 | + # QUAY_PUBLISH. |
| 9 | + # To set this up, sign up for quay.io (you can connect it to your github) |
| 10 | + # then create a robot user with write access user called "bcc_buildbot", |
| 11 | + # and add the secret token for it to GitHub secrets as: |
| 12 | + # - QUAY_TOKEN = <token from quay.io> |
| 13 | + name: Publish to quay.io |
| 14 | + runs-on: ubuntu-latest |
| 15 | + strategy: |
| 16 | + matrix: |
| 17 | + env: |
| 18 | + - NAME: xenial-release |
| 19 | + OS_RELEASE: 16.04 |
| 20 | + - NAME: bionic-release |
| 21 | + OS_RELEASE: 18.04 |
| 22 | + steps: |
| 23 | + |
| 24 | + - uses: actions/checkout@v1 |
| 25 | + |
| 26 | + - name: Initialize workflow variables |
| 27 | + id: vars |
| 28 | + shell: bash |
| 29 | + run: | |
| 30 | + if [ -n "${QUAY_TOKEN}" ];then |
| 31 | + echo "Quay token is set, will push an image" |
| 32 | + echo ::set-output name=QUAY_PUBLISH::true |
| 33 | + else |
| 34 | + echo "Quay token not set, skipping" |
| 35 | + fi |
| 36 | +
|
| 37 | + env: |
| 38 | + QUAY_TOKEN: ${{ secrets.QUAY_TOKEN }} |
| 39 | + |
| 40 | + - name: Authenticate with quay.io docker registry |
| 41 | + if: > |
| 42 | + steps.vars.outputs.QUAY_PUBLISH |
| 43 | + env: |
| 44 | + QUAY_TOKEN: ${{ secrets.QUAY_TOKEN }} |
| 45 | + run: ./scripts/docker/auth.sh ${{ github.repository }} |
| 46 | + |
| 47 | + - name: Package docker image and push to quay.io |
| 48 | + if: > |
| 49 | + steps.vars.outputs.QUAY_PUBLISH |
| 50 | + run: > |
| 51 | + ./scripts/docker/push.sh |
| 52 | + ${{ github.repository }} |
| 53 | + ${{ github.ref }} |
| 54 | + ${{ github.sha }} |
| 55 | + ${{ matrix.env['NAME'] }} |
| 56 | + ${{ matrix.env['OS_RELEASE'] }} |
| 57 | +
|
| 58 | + # Uploads the packages built in docker to the github build as an artifact for convenience |
| 59 | + - uses: actions/upload-artifact@v1 |
| 60 | + with: |
| 61 | + name: ${{ matrix.env['NAME'] }} |
| 62 | + path: output |
| 63 | + |
| 64 | + # Optionally publish container images to custom docker repository, |
| 65 | + # guarded by presence of all required github secrets. |
| 66 | + # GitHub secrets can be configured as follows: |
| 67 | + # - DOCKER_IMAGE = docker.io/myorg/bcc |
| 68 | + # - DOCKER_USERNAME = username |
| 69 | + # - DOCKER_PASSWORD = password |
| 70 | + publish_dockerhub: |
| 71 | + name: Publish To Dockerhub |
| 72 | + runs-on: ubuntu-latest |
| 73 | + steps: |
| 74 | + |
| 75 | + - uses: actions/checkout@v1 |
| 76 | + |
| 77 | + - name: Initialize workflow variables |
| 78 | + id: vars |
| 79 | + shell: bash |
| 80 | + run: | |
| 81 | + if [ -n "${DOCKER_IMAGE}" ] && \ |
| 82 | + [ -n "${DOCKER_USERNAME}" ] && \ |
| 83 | + [ -n "${DOCKER_PASSWORD}" ];then |
| 84 | + echo "Custom docker credentials set, will push an image" |
| 85 | + echo ::set-output name=DOCKER_PUBLISH::true |
| 86 | + else |
| 87 | + echo "Custom docker credentials not, skipping" |
| 88 | + fi |
| 89 | +
|
| 90 | + - name: Build container image and publish to registry |
| 91 | + id: publish-registry |
| 92 | + |
| 93 | + if: ${{ steps.vars.outputs.DOCKER_PUBLISH }} |
| 94 | + with: |
| 95 | + name: ${{ secrets.DOCKER_IMAGE }} |
| 96 | + username: ${{ secrets.DOCKER_USERNAME }} |
| 97 | + password: ${{ secrets.DOCKER_PASSWORD }} |
| 98 | + workdir: . |
| 99 | + dockerfile: Dockerfile.ubuntu |
| 100 | + snapshot: true |
| 101 | + cache: ${{ github.event_name != 'schedule' }} |
0 commit comments