|
| 1 | +name: Build and Package the CouchDB Loader Util to Dev Registry |
| 2 | +on: |
| 3 | + push: |
| 4 | + branches: [ main ] |
| 5 | +env: |
| 6 | + DEV_REGISTRY: ghcr.io/noaa-gsl/idss/commons/python |
| 7 | +jobs: |
| 8 | + build: |
| 9 | + runs-on: ubuntu-latest |
| 10 | + strategy: |
| 11 | + fail-fast: true |
| 12 | + matrix: |
| 13 | + app: |
| 14 | + - couch-loader |
| 15 | + steps: |
| 16 | + |
| 17 | + - name: Checkout Code |
| 18 | + uses: actions/checkout@v2 |
| 19 | + |
| 20 | + - name: Set ENV Variables |
| 21 | + shell: bash |
| 22 | + run: | |
| 23 | + DATE=$(git show -s --format=%cd --date=format:'%Y-%m-%d.%H:%M:%S.%z' ${{ github.sha }}) |
| 24 | + if [[ "${GITHUB_EVENT_NAME}" == "pull_request" ]]; then |
| 25 | + # PR build |
| 26 | + echo "BRANCH=${GITHUB_HEAD_REF}" >> $GITHUB_ENV |
| 27 | + echo "VERSION=dev-${{ github.sha }}-$DATE" >> $GITHUB_ENV |
| 28 | + elif [[ "${GITHUB_EVENT_NAME}" == "push" ]]; then |
| 29 | + # Handle differences between branches/tags |
| 30 | + if [[ "${GITHUB_REF}" == *"heads"* ]]; then |
| 31 | + # Branch build |
| 32 | + echo "BRANCH=${GITHUB_REF#refs/heads/}" >> $GITHUB_ENV |
| 33 | + echo "VERSION=dev-${{ github.sha }}-$DATE" >> $GITHUB_ENV |
| 34 | + elif [[ "${GITHUB_REF}" == *"tags"* ]]; then |
| 35 | + # Tag build |
| 36 | + echo "BRANCH=${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV |
| 37 | + echo "VERSION=${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV |
| 38 | + else |
| 39 | + echo "ERROR: Unanticipated Git Ref" |
| 40 | + exit 1 |
| 41 | + fi |
| 42 | + else |
| 43 | + echo "ERROR: Unanticipated GitHub Event" |
| 44 | + exit 1 |
| 45 | + fi |
| 46 | +
|
| 47 | + - name: Create App Names |
| 48 | + env: |
| 49 | + APP: '${{matrix.app}}' |
| 50 | + run: | |
| 51 | + echo "APP_LOWERCASE=${APP,,}" >> $GITHUB_ENV |
| 52 | +
|
| 53 | + - name: Build Image |
| 54 | + run: | |
| 55 | + docker build \ |
| 56 | + --build-arg APPNAME=${{matrix.app}} \ |
| 57 | + --build-arg BUILDVER="${{env.VERSION}}" \ |
| 58 | + --build-arg COMMITBRANCH=${{env.BRANCH}} \ |
| 59 | + --build-arg COMMITSHA=${{github.sha}} \ |
| 60 | + -t ${{env.DEV_REGISTRY}}/${{env.APP_LOWERCASE}}:${{env.BRANCH}} \ |
| 61 | + -f ./docker/python/Dockerfile . |
| 62 | +
|
| 63 | + - name: Run Trivy vulnerability scanner |
| 64 | + uses: aquasecurity/trivy-action@master |
| 65 | + with: |
| 66 | + image-ref: '${{env.DEV_REGISTRY}}/${{env.APP_LOWERCASE}}:${{env.BRANCH}}' |
| 67 | + format: 'table' |
| 68 | + #exit-code: '1' |
| 69 | + ignore-unfixed: true |
| 70 | + vuln-type: 'os,library' |
| 71 | + severity: 'CRITICAL,HIGH' |
| 72 | + scanners: 'vuln' |
| 73 | + |
| 74 | + # this requires public repo / additional config |
| 75 | + #format: 'sarif' |
| 76 | + #output: 'trivy-results.sarif' |
| 77 | + |
| 78 | + # GSL isn't paying for this support with private repositories |
| 79 | +# - name: Upload Trivy scan results to GitHub Security tab |
| 80 | +# uses: github/codeql-action/upload-sarif@v2 |
| 81 | +# with: |
| 82 | +# sarif_file: 'trivy-results.sarif' |
| 83 | + |
| 84 | + - name: Login to GitHub Container Registry |
| 85 | + uses: docker/login-action@v1 |
| 86 | + with: |
| 87 | + registry: ghcr.io |
| 88 | + username: ${{github.actor}} |
| 89 | + password: ${{secrets.GITHUB_TOKEN}} |
| 90 | + |
| 91 | + - name: Push Image to Dev Registry |
| 92 | + run: | |
| 93 | + docker push ${{env.DEV_REGISTRY}}/${{env.APP_LOWERCASE}}:${{env.BRANCH}} |
0 commit comments