|
| 1 | +name: "[Dispatch] Build Dev" |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + |
| 6 | +env: |
| 7 | + SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} |
| 8 | + |
| 9 | +jobs: |
| 10 | + versioning: |
| 11 | + runs-on: ubuntu-latest |
| 12 | + outputs: |
| 13 | + version: ${{ steps.versioning.outputs.VERSION }} |
| 14 | + steps: |
| 15 | + - uses: actions/checkout@v2 |
| 16 | + - name: get current date |
| 17 | + run: | |
| 18 | + sudo ln -sf /usr/share/zoneinfo/Asia/Seoul /etc/localtime |
| 19 | + echo "TIME=$(date +'%Y%m%d.%H%M%S')" >> $GITHUB_ENV |
| 20 | + - name: set version with current date |
| 21 | + id: versioning |
| 22 | + run: | |
| 23 | + echo "VERSION=$(cat src/VERSION | cut -c 2-).${{ env.TIME }}" >> $GITHUB_OUTPUT |
| 24 | + - name: Notice when job fails |
| 25 | + if: failure() |
| 26 | + uses: 8398a7/action-slack@v3.2.0 |
| 27 | + with: |
| 28 | + status: ${{job.status}} |
| 29 | + fields: repo,workflow,job |
| 30 | + author_name: Github Action Slack |
| 31 | + |
| 32 | + docker: |
| 33 | + if: github.repository_owner == 'cloudforet-io' |
| 34 | + needs: versioning |
| 35 | + runs-on: ubuntu-latest |
| 36 | + env: |
| 37 | + VERSION: ${{ needs.versioning.outputs.version }} |
| 38 | + steps: |
| 39 | + - name: Checkout |
| 40 | + uses: actions/checkout@v3 |
| 41 | + with: |
| 42 | + token: ${{ secrets.PAT_TOKEN }} |
| 43 | + |
| 44 | + - name: get service name |
| 45 | + run: | |
| 46 | + echo "SERVICE=$(echo ${{ github.repository }} | cut -d '/' -f2)" >> $GITHUB_ENV |
| 47 | + |
| 48 | + - name: Set up QEMU |
| 49 | + uses: docker/setup-qemu-action@v2 |
| 50 | + |
| 51 | + - name: Set up Docker Buildx |
| 52 | + uses: docker/setup-buildx-action@v2 |
| 53 | + |
| 54 | + - name: Login to Docker Hub |
| 55 | + uses: docker/login-action@v2 |
| 56 | + with: |
| 57 | + username: ${{ secrets.DOCKER_USERNAME }} |
| 58 | + password: ${{ secrets.DOCKER_PASSWORD }} |
| 59 | + |
| 60 | + - name: Build and push to pyengine |
| 61 | + uses: docker/build-push-action@v4 |
| 62 | + with: |
| 63 | + context: . |
| 64 | + platform: ${{ env.ARCH }} |
| 65 | + push: true |
| 66 | + tags: pyengine/${{ env.SERVICE }}:${{ env.VERSION }} |
| 67 | + |
| 68 | + - name: Notice when job fails |
| 69 | + if: failure() |
| 70 | + uses: 8398a7/action-slack@v3.2.0 |
| 71 | + with: |
| 72 | + status: ${{job.status}} |
| 73 | + fields: repo,workflow,job |
| 74 | + author_name: Github Action Slack |
| 75 | + |
| 76 | + scan: |
| 77 | + needs: [versioning, docker] |
| 78 | + runs-on: ubuntu-20.04 |
| 79 | + env: |
| 80 | + VERSION: ${{ needs.versioning.outputs.version }} |
| 81 | + steps: |
| 82 | + - name: Run Trivy vulnerability scanner |
| 83 | + id: trivy-scan |
| 84 | + uses: aquasecurity/trivy-action@master |
| 85 | + with: |
| 86 | + image-ref: pyengine/${{ github.event.repository.name }}:${{ env.VERSION }} |
| 87 | + format: 'sarif' |
| 88 | + output: 'trivy-results.sarif' |
| 89 | + ignore-unfixed: true |
| 90 | + vuln-type: 'os,library' |
| 91 | + severity: 'CRITICAL,HIGH' |
| 92 | + |
| 93 | + - name: Upload Trivy scan results to GitHub Security tab |
| 94 | + uses: github/codeql-action/upload-sarif@v2 |
| 95 | + with: |
| 96 | + sarif_file: 'trivy-results.sarif' |
| 97 | + |
| 98 | + - name: Count vulnerabilities |
| 99 | + id: vulnerabilities |
| 100 | + run: | |
| 101 | + count=$(jq '.runs[].results[].ruleId' ./trivy-results.sarif | wc -c) |
| 102 | + echo "result_count=$count" >> $GITHUB_OUTPUT |
| 103 | + echo "$count" |
| 104 | +
|
| 105 | + - name: slack |
| 106 | + if: ${{ steps.vulnerabilities.outputs.result_count != 0 }} |
| 107 | + uses: 8398a7/action-slack@v3 |
| 108 | + with: |
| 109 | + status: custom |
| 110 | + fields: workflowRun |
| 111 | + custom_payload: | |
| 112 | + { |
| 113 | + "blocks": [ |
| 114 | + { |
| 115 | + "type": "section", |
| 116 | + "text": { |
| 117 | + "type": "mrkdwn", |
| 118 | + "text": ":warning: Image vulnerability detected" |
| 119 | + } |
| 120 | + }, |
| 121 | + { |
| 122 | + "type": "section", |
| 123 | + "fields": [ |
| 124 | + { |
| 125 | + "type": "mrkdwn", |
| 126 | + "text": "*Image:*\npyengine/${{ github.event.repository.name }}:${{ env.VERSION }}" |
| 127 | + }, |
| 128 | + { |
| 129 | + "type": "mrkdwn", |
| 130 | + "text": "*Repo name:*\n${{ github.repository }}" |
| 131 | + } |
| 132 | + ] |
| 133 | + }, |
| 134 | + { |
| 135 | + "type": "actions", |
| 136 | + "elements": [ |
| 137 | + { |
| 138 | + "type": "button", |
| 139 | + "text": { |
| 140 | + "type": "plain_text", |
| 141 | + "emoji": true, |
| 142 | + "text": "View Detail" |
| 143 | + }, |
| 144 | + "style": "danger", |
| 145 | + "url": "https://github.com/${{ github.repository }}/security/code-scanning" |
| 146 | + } |
| 147 | + ] |
| 148 | + } |
| 149 | + ] |
| 150 | + } |
| 151 | + env: |
| 152 | + SLACK_WEBHOOK_URL: ${{secrets.VULNERABILITY_SLACK_WEBHOOK_URL}} |
| 153 | + |
| 154 | + notification: |
| 155 | + runs-on: ubuntu-latest |
| 156 | + needs: docker |
| 157 | + steps: |
| 158 | + - name: Slack |
| 159 | + if: always() |
| 160 | + uses: 8398a7/action-slack@v3.2.0 |
| 161 | + with: |
| 162 | + status: ${{job.status}} |
| 163 | + fields: repo,message,commit,author,action,ref,workflow,job |
| 164 | + author_name: Github Action Slack |
0 commit comments