feat: improve ci #2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Docker | |
| on: | |
| push: | |
| branches: [main] | |
| tags: ["v*"] | |
| pull_request: | |
| paths: | |
| - "Dockerfile*" | |
| - ".dockerignore" | |
| - "Makefile" | |
| - ".github/workflows/docker.yml" | |
| concurrency: | |
| group: ${{ github.workflow }}-${{ github.ref }} | |
| cancel-in-progress: true | |
| jobs: | |
| # ============================================================================ | |
| # Docker Build & Push (uses Makefile) | |
| # ============================================================================ | |
| docker: | |
| name: Docker Build & Push | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| - name: Log in to Docker Hub | |
| if: github.event_name != 'pull_request' | |
| uses: docker/login-action@v3 | |
| with: | |
| username: ${{ secrets.DOCKERHUB_USERNAME }} | |
| password: ${{ secrets.DOCKERHUB_TOKEN }} | |
| - name: Setup Rust (for cross-compilation) | |
| uses: dtolnay/rust-toolchain@stable | |
| - name: Cache Rust dependencies | |
| uses: Swatinem/rust-cache@v2 | |
| - name: Install development tools | |
| run: make tools | |
| - name: Install cross-compilation tools | |
| run: | | |
| cargo install cross --locked | |
| docker run --rm --privileged multiarch/qemu-user-static --reset -p yes | |
| - name: Determine Docker image tag | |
| id: tag | |
| run: | | |
| if [[ "${{ github.ref }}" == "refs/heads/main" ]]; then | |
| echo "tag=latest" >> "$GITHUB_OUTPUT" | |
| elif [[ "${{ github.ref }}" == refs/tags/* ]]; then | |
| echo "tag=${GITHUB_REF#refs/tags/}" >> "$GITHUB_OUTPUT" | |
| else | |
| echo "tag=pr-${{ github.event.number }}" >> "$GITHUB_OUTPUT" | |
| fi | |
| - name: Build and push Docker image | |
| if: github.event_name != 'pull_request' | |
| run: make docker-build-push | |
| env: | |
| DOCKER_IMAGE_NAME: loadnetwork/ultramarine | |
| - name: Build Docker image (PR only) | |
| if: github.event_name == 'pull_request' | |
| run: make docker-build | |
| - name: Run container security scan | |
| if: github.event_name != 'pull_request' | |
| uses: aquasecurity/trivy-action@master | |
| with: | |
| image-ref: loadnetwork/ultramarine:${{ steps.tag.outputs.tag }} | |
| format: sarif | |
| output: trivy-results.sarif | |
| - name: Upload security scan results | |
| if: github.event_name != 'pull_request' | |
| uses: github/codeql-action/upload-sarif@v3 | |
| with: | |
| sarif_file: trivy-results.sarif |