build_docker_parser.yaml 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. name: "[searcher] build container image"
  2. on:
  3. push:
  4. branches: ["main"]
  5. tags: ["v*.*.*"]
  6. pull_request:
  7. branches: ["main"]
  8. env:
  9. REGISTRY: ghcr.io
  10. IMAGE_NAME: ${{ github.repository }}
  11. GCP_REGISTRY: asia-northeast1-docker.pkg.dev
  12. GCP_IMAGE_NAME: iwanhae/cloudrun/kuberian
  13. jobs:
  14. build:
  15. runs-on: ubuntu-latest
  16. permissions:
  17. contents: read
  18. packages: write
  19. id-token: write
  20. steps:
  21. - name: Checkout repository
  22. uses: actions/checkout@v3
  23. - id: "auth"
  24. uses: "google-github-actions/auth@v1"
  25. with:
  26. credentials_json: "${{ secrets.GOOGLE_CLOUD_SERVICE_ACCOUNT }}"
  27. - name: "Set up Cloud SDK"
  28. uses: "google-github-actions/setup-gcloud@v1"
  29. - name: "Configure Docker CLI"
  30. run: "gcloud auth configure-docker ${{ env.GCP_REGISTRY }}"
  31. - name: Setup Docker buildx
  32. uses: docker/setup-buildx-action@v2.9.1
  33. - name: Log into registry ${{ env.REGISTRY }}
  34. if: github.event_name != 'pull_request'
  35. uses: docker/login-action@v2.2.0
  36. with:
  37. registry: ${{ env.REGISTRY }}
  38. username: ${{ github.actor }}
  39. password: ${{ secrets.GITHUB_TOKEN }}
  40. - name: Extract Docker metadata for GHCR
  41. id: meta
  42. uses: docker/metadata-action@v4.6.0
  43. with:
  44. images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
  45. tags: |
  46. type=raw,value=latest,enable=${{ github.ref == format('refs/heads/{0}', 'main') }}
  47. type=semver,pattern={{version}}
  48. - name: Extract Docker metadata for GCR
  49. id: meta-gcr
  50. uses: docker/metadata-action@v4.6.0
  51. with:
  52. images: ${{ env.GCP_REGISTRY }}/${{ env.GCP_IMAGE_NAME }}
  53. tags: |
  54. type=raw,value=latest,enable=${{ github.ref == format('refs/heads/{0}', 'main') }}
  55. type=semver,pattern={{version}}
  56. - name: Build and Push cache
  57. id: build-and-push-cache
  58. uses: docker/build-push-action@v4.1.1
  59. with:
  60. context: ./searcher
  61. push: false
  62. tags: ${{ steps.meta.outputs.tags }}
  63. labels: ${{ steps.meta.outputs.labels }}
  64. target: builder
  65. cache-from: type=gha
  66. cache-to: type=gha,mode=max
  67. - name: Build and Push to GCR
  68. id: build-and-push-gcr
  69. uses: docker/build-push-action@v4.1.1
  70. with:
  71. context: ./searcher
  72. push: ${{ github.event_name != 'pull_request' }}
  73. tags: ${{ steps.meta-gcr.outputs.tags }}
  74. labels: ${{ steps.meta-gcr.outputs.labels }}
  75. cache-from: type=gha