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