|
| 1 | +name: push |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: master |
| 6 | + release: |
| 7 | + types: [published] |
| 8 | + |
| 9 | +jobs: |
| 10 | + main: |
| 11 | + runs-on: ubuntu-latest |
| 12 | + permissions: |
| 13 | + security-events: write |
| 14 | + actions: read |
| 15 | + contents: read |
| 16 | + |
| 17 | + steps: |
| 18 | + - uses: actions/checkout@v4 |
| 19 | + |
| 20 | + - uses: actions/setup-node@v4 |
| 21 | + with: |
| 22 | + cache: 'npm' |
| 23 | + |
| 24 | + - run: | |
| 25 | + REV=`git rev-parse HEAD | rev | cut -c 1-6 | rev` |
| 26 | + echo "VITE_APP_BUILD=..$REV" >> .env.production |
| 27 | + cat .env.production |
| 28 | +
|
| 29 | + - run: npm install |
| 30 | + - run: npm run build |
| 31 | + |
| 32 | + - run: | |
| 33 | + ls -al dist/ |
| 34 | +
|
| 35 | + - name: Prepare |
| 36 | + id: prep |
| 37 | + run: | |
| 38 | + DOCKER_IMAGE=mpse2/kegmonapp |
| 39 | + VERSION=latest |
| 40 | + SHORTREF=${GITHUB_SHA::8} |
| 41 | +
|
| 42 | + # If this is git tag, use the tag name as a docker tag |
| 43 | + if [[ $GITHUB_REF == refs/tags/* ]]; then |
| 44 | + VERSION=${GITHUB_REF#refs/tags/v} |
| 45 | + fi |
| 46 | + TAGS="${DOCKER_IMAGE}:${VERSION},${DOCKER_IMAGE}:${SHORTREF}" |
| 47 | +
|
| 48 | + # If the VERSION looks like a version number, assume that |
| 49 | + # this is the most recent version of the image and also |
| 50 | + # tag it 'latest'. |
| 51 | + if [[ $VERSION =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]; then |
| 52 | + TAGS="$TAGS,${DOCKER_IMAGE}:latest" |
| 53 | + fi |
| 54 | +
|
| 55 | + # Set output parameters. |
| 56 | + echo "tags=${TAGS}" >> $GITHUB_OUTPUT |
| 57 | + echo "docker_image=${DOCKER_IMAGE}" >> $GITHUB_OUTPUT |
| 58 | + cat $GITHUB_OUTPUT |
| 59 | +
|
| 60 | + - name: Set up QEMU |
| 61 | + id: qemu |
| 62 | + uses: docker/setup-qemu-action@v1 |
| 63 | + with: |
| 64 | + image: tonistiigi/binfmt:latest |
| 65 | + platforms: all |
| 66 | + |
| 67 | + - name: Set up Docker Buildx |
| 68 | + id: buildx |
| 69 | + uses: docker/setup-buildx-action@v1 |
| 70 | + |
| 71 | + - name: Login to DockerHub |
| 72 | + if: github.event_name != 'pull_request' |
| 73 | + uses: docker/login-action@v1 |
| 74 | + with: |
| 75 | + username: ${{ secrets.DOCKER_USERNAME }} |
| 76 | + password: ${{ secrets.DOCKER_PASSWORD }} |
| 77 | + |
| 78 | + - name: Build |
| 79 | + uses: docker/build-push-action@v2 |
| 80 | + with: |
| 81 | + builder: ${{ steps.buildx.outputs.name }} |
| 82 | + context: ./ |
| 83 | + file: ./Dockerfile |
| 84 | + platforms: linux/amd64 |
| 85 | + push: true |
| 86 | + tags: ${{ steps.prep.outputs.tags }} |
| 87 | + |
| 88 | + #- name: Run Trivy vulnerability scanner |
| 89 | + # uses: aquasecurity/trivy-action@master |
| 90 | + # with: |
| 91 | + # image-ref: 'docker.io/mpse2/kegmonapp:latest' |
| 92 | + # format: 'template' |
| 93 | + # template: '@/contrib/sarif.tpl' |
| 94 | + # output: 'trivy-results.sarif' |
| 95 | +# # severity: 'UNKNOWN,LOW,MEDIUM,HIGH,CRITICAL' |
| 96 | +# severity: 'HIGH,CRITICAL' |
| 97 | + |
| 98 | +#- name: 'Upload Artifact' |
| 99 | +# uses: actions/upload-artifact@v2 |
| 100 | +# with: |
| 101 | +# name: 'trivy-results.sarif' |
| 102 | +# path: 'trivy-results.sarif' |
| 103 | +# retention-days: 5 |
| 104 | + |
| 105 | +#- name: Upload Trivy scan results to GitHub Security tab |
| 106 | +# uses: github/codeql-action/upload-sarif@v2 |
| 107 | +# with: |
| 108 | +# sarif_file: 'trivy-results.sarif' |
0 commit comments