build_docker_parser.yaml 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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: |
  67. type=gha,mode=max
  68. type=local,dest=~/cache
  69. - name: Build and Push to GCR
  70. id: build-and-push-gcr
  71. uses: docker/build-push-action@v4.1.1
  72. with:
  73. context: ./searcher
  74. push: ${{ github.event_name != 'pull_request' }}
  75. tags: ${{ steps.meta-gcr.outputs.tags }}
  76. labels: ${{ steps.meta-gcr.outputs.labels }}
  77. cache-from: type=local,src=~/cache