|
| 1 | +# name: Build and Push Docker Image |
| 2 | + |
| 3 | +# on: |
| 4 | +# push: |
| 5 | +# branches: |
| 6 | +# - main |
| 7 | +# paths: |
| 8 | +# - 'backend/**' |
| 9 | +# - 'frontend/**' |
| 10 | +# - 'docker-compose.yml' |
| 11 | +# - '.github/workflows/docker-build-push.yml' |
| 12 | +# pull_request: |
| 13 | +# branches: |
| 14 | +# - main |
| 15 | +# paths: |
| 16 | +# - 'backend/**' |
| 17 | +# - 'frontend/**' |
| 18 | +# - 'docker-compose.yml' |
| 19 | +# - '.github/workflows/docker-build-push.yml' |
| 20 | + |
| 21 | +# env: |
| 22 | +# REGISTRY: docker.io |
| 23 | +# BACKEND_IMAGE_NAME: mathmodelagent-backend |
| 24 | +# FRONTEND_IMAGE_NAME: mathmodelagent-frontend |
| 25 | + |
| 26 | +# jobs: |
| 27 | +# build-backend: |
| 28 | +# runs-on: ubuntu-latest |
| 29 | +# outputs: |
| 30 | +# image-tag: ${{ steps.meta.outputs.tags }} |
| 31 | +# image-digest: ${{ steps.build.outputs.digest }} |
| 32 | + |
| 33 | +# steps: |
| 34 | +# - name: Checkout code |
| 35 | +# uses: actions/checkout@v4 |
| 36 | + |
| 37 | +# - name: Set up Docker Buildx |
| 38 | +# uses: docker/setup-buildx-action@v3 |
| 39 | + |
| 40 | +# - name: Log in to Docker Hub |
| 41 | +# if: github.event_name != 'pull_request' |
| 42 | +# uses: docker/login-action@v3 |
| 43 | +# with: |
| 44 | +# registry: ${{ env.REGISTRY }} |
| 45 | +# username: ${{ secrets.DOCKER_USERNAME }} |
| 46 | +# password: ${{ secrets.DOCKER_PASSWORD }} |
| 47 | + |
| 48 | +# - name: Extract metadata for backend |
| 49 | +# id: meta |
| 50 | +# uses: docker/metadata-action@v5 |
| 51 | +# with: |
| 52 | +# images: ${{ env.REGISTRY }}/${{ secrets.DOCKER_USERNAME }}/${{ env.BACKEND_IMAGE_NAME }} |
| 53 | +# tags: | |
| 54 | +# type=ref,event=branch |
| 55 | +# type=ref,event=pr |
| 56 | +# type=sha,prefix={{branch}}- |
| 57 | +# type=raw,value=latest,enable={{is_default_branch}} |
| 58 | + |
| 59 | +# - name: Build and push backend Docker image |
| 60 | +# id: build |
| 61 | +# uses: docker/build-push-action@v5 |
| 62 | +# with: |
| 63 | +# context: ./backend |
| 64 | +# file: ./backend/Dockerfile |
| 65 | +# push: ${{ github.event_name != 'pull_request' }} |
| 66 | +# tags: ${{ steps.meta.outputs.tags }} |
| 67 | +# labels: ${{ steps.meta.outputs.labels }} |
| 68 | +# cache-from: type=gha |
| 69 | +# cache-to: type=gha,mode=max |
| 70 | +# platforms: linux/amd64,linux/arm64 |
| 71 | + |
| 72 | +# build-frontend: |
| 73 | +# runs-on: ubuntu-latest |
| 74 | +# outputs: |
| 75 | +# image-tag: ${{ steps.meta.outputs.tags }} |
| 76 | +# image-digest: ${{ steps.build.outputs.digest }} |
| 77 | + |
| 78 | +# steps: |
| 79 | +# - name: Checkout code |
| 80 | +# uses: actions/checkout@v4 |
| 81 | + |
| 82 | +# - name: Set up Docker Buildx |
| 83 | +# uses: docker/setup-buildx-action@v3 |
| 84 | + |
| 85 | +# - name: Log in to Docker Hub |
| 86 | +# if: github.event_name != 'pull_request' |
| 87 | +# uses: docker/login-action@v3 |
| 88 | +# with: |
| 89 | +# registry: ${{ env.REGISTRY }} |
| 90 | +# username: ${{ secrets.DOCKER_USERNAME }} |
| 91 | +# password: ${{ secrets.DOCKER_PASSWORD }} |
| 92 | + |
| 93 | +# - name: Extract metadata for frontend |
| 94 | +# id: meta |
| 95 | +# uses: docker/metadata-action@v5 |
| 96 | +# with: |
| 97 | +# images: ${{ env.REGISTRY }}/${{ secrets.DOCKER_USERNAME }}/${{ env.FRONTEND_IMAGE_NAME }} |
| 98 | +# tags: | |
| 99 | +# type=ref,event=branch |
| 100 | +# type=ref,event=pr |
| 101 | +# type=sha,prefix={{branch}}- |
| 102 | +# type=raw,value=latest,enable={{is_default_branch}} |
| 103 | + |
| 104 | +# - name: Build and push frontend Docker image |
| 105 | +# id: build |
| 106 | +# uses: docker/build-push-action@v5 |
| 107 | +# with: |
| 108 | +# context: ./frontend |
| 109 | +# file: ./frontend/Dockerfile |
| 110 | +# push: ${{ github.event_name != 'pull_request' }} |
| 111 | +# tags: ${{ steps.meta.outputs.tags }} |
| 112 | +# labels: ${{ steps.meta.outputs.labels }} |
| 113 | +# cache-from: type=gha |
| 114 | +# cache-to: type=gha,mode=max |
| 115 | +# platforms: linux/amd64,linux/arm64 |
| 116 | + |
| 117 | +# security-scan: |
| 118 | +# runs-on: ubuntu-latest |
| 119 | +# needs: [build-backend, build-frontend] |
| 120 | +# if: github.event_name != 'pull_request' |
| 121 | + |
| 122 | +# strategy: |
| 123 | +# matrix: |
| 124 | +# component: [backend, frontend] |
| 125 | + |
| 126 | +# steps: |
| 127 | +# - name: Run Trivy vulnerability scanner |
| 128 | +# uses: aquasecurity/trivy-action@master |
| 129 | +# with: |
| 130 | +# image-ref: ${{ needs[format('build-{0}', matrix.component)].outputs.image-tag }} |
| 131 | +# format: 'sarif' |
| 132 | +# output: 'trivy-results-${{ matrix.component }}.sarif' |
| 133 | + |
| 134 | +# - name: Upload Trivy scan results to GitHub Security tab |
| 135 | +# uses: github/codeql-action/upload-sarif@v3 |
| 136 | +# if: always() |
| 137 | +# with: |
| 138 | +# sarif_file: 'trivy-results-${{ matrix.component }}.sarif' |
0 commit comments