-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
👷 Update CI/CD for cloudrun #113
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.nuxt | ||
.output | ||
node_modules |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
name: Delete Cloud Run (PR closed) | ||
on: | ||
pull_request: | ||
branches: | ||
- main | ||
types: | ||
- closed | ||
jobs: | ||
build-and-deploy: | ||
runs-on: ubuntu-latest | ||
permissions: | ||
contents: read | ||
id-token: write | ||
steps: | ||
- name: Login to Google Cloud | ||
id: auth | ||
uses: google-github-actions/auth@v2 | ||
with: | ||
token_format: access_token | ||
workload_identity_provider: 'projects/292061085119/locations/global/workloadIdentityPools/github-pool/providers/provider-github' | ||
service_account: 'gh-actions@ynufes-hp-cloudrun.iam.gserviceaccount.com' | ||
|
||
- name: setup gcloud | ||
uses: google-github-actions/setup-gcloud@v2 | ||
with: | ||
version: '>= 363.0.0' | ||
|
||
- name: Delete Cloud Run | ||
id: delete-cloudrun-service | ||
continue-on-error: true | ||
run: | | ||
gcloud run services delete tokiwa23-stg-pr-${{ github.event.number }} --region=asia-northeast1 --quiet | ||
|
||
- name: Delete from Artifact Registry | ||
id: delete-artifact-registry | ||
continue-on-error: true | ||
run: | | ||
gcloud artifacts docker images delete asia-northeast1-docker.pkg.dev/ynufes-hp-cloudrun/staging/tokiwa23-pr-${{ github.event.number }}:latest --quiet | ||
|
||
- name: Notify Failure on Pull Request | ||
if: ${{ steps.delete-cloudrun-service.outcome != 'success' || steps.delete-artifact-registry.outcome != 'success' }} | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
run: | | ||
gh pr comment ${{ github.event.number }} -m "Failed to delete resources, CloudRun: ${{ steps.delete-cloudrun-service.outcome }}, Artifact Registry: ${{ steps.delete-artifact-registry.outcome }}" | ||
exit 1 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
name: Deploy to Cloud Run (PR preview) | ||
on: | ||
pull_request: | ||
branches: | ||
- main | ||
types: | ||
- opened | ||
- synchronize | ||
- reopened | ||
jobs: | ||
build-and-deploy: | ||
runs-on: ubuntu-latest | ||
permissions: | ||
contents: read | ||
id-token: write | ||
pull-requests: write | ||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v4 | ||
|
||
- name: Set up Docker Buildx | ||
uses: docker/setup-buildx-action@v3 | ||
|
||
- name: Login to Google Cloud | ||
id: auth | ||
uses: google-github-actions/auth@v2 | ||
with: | ||
token_format: access_token | ||
workload_identity_provider: 'projects/292061085119/locations/global/workloadIdentityPools/github-pool/providers/provider-github' | ||
service_account: 'gh-actions@ynufes-hp-cloudrun.iam.gserviceaccount.com' | ||
|
||
- name: Set up Cloud SDK | ||
uses: 'google-github-actions/setup-gcloud@v2' | ||
with: | ||
version: '>= 363.0.0' | ||
|
||
- name: Authorize Docker | ||
id: docker-auth | ||
uses: docker/login-action@v2 | ||
with: | ||
username: 'oauth2accesstoken' | ||
password: ${{ steps.auth.outputs.access_token }} | ||
registry: asia-northeast1-docker.pkg.dev | ||
|
||
- name: Build and push Docker image | ||
uses: docker/build-push-action@v5 | ||
with: | ||
push: true | ||
tags: asia-northeast1-docker.pkg.dev/ynufes-hp-cloudrun/staging/tokiwa23-pr-${{ github.event.number }}:latest | ||
context: . | ||
file: ./cloudrun/Dockerfile | ||
|
||
- name: Deploy to Cloud Run | ||
id: deploy | ||
uses: google-github-actions/deploy-cloudrun@v2 | ||
with: | ||
service: tokiwa23-stg-pr-${{ github.event.number }} | ||
region: "asia-northeast1" | ||
image: asia-northeast1-docker.pkg.dev/ynufes-hp-cloudrun/staging/tokiwa23-pr-${{ github.event.number }}:latest | ||
|
||
- name: Make CloudRun accessible | ||
run: | | ||
gcloud run services add-iam-policy-binding tokiwa23-stg-pr-${{ github.event.number }} --region=asia-northeast1 --member=allUsers --role=roles/run.invoker | ||
|
||
- name: Post comments | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
URL: ${{ github.event.pull_request.html_url }} | ||
run: | ||
gh pr comment -b "Deployed on ${{ steps.deploy.outputs.url }}" ${{ github.event.number }} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
name: Deploy to Cloud Run (Release) | ||
on: | ||
push: | ||
branches: | ||
- release | ||
jobs: | ||
build-and-deploy: | ||
runs-on: ubuntu-latest | ||
permissions: | ||
contents: 'read' | ||
id-token: 'write' | ||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v4 | ||
|
||
- name: Set up Docker Buildx | ||
uses: docker/setup-buildx-action@v3 | ||
|
||
- name: Login to Google Cloud | ||
id: auth | ||
uses: google-github-actions/auth@v2 | ||
with: | ||
token_format: access_token | ||
workload_identity_provider: 'projects/292061085119/locations/global/workloadIdentityPools/github-pool/providers/provider-github' | ||
service_account: 'gh-actions@ynufes-hp-cloudrun.iam.gserviceaccount.com' | ||
|
||
- name: Set up Cloud SDK | ||
uses: 'google-github-actions/setup-gcloud@v2' | ||
with: | ||
version: '>= 363.0.0' | ||
|
||
- name: Authorize Docker | ||
id: docker-auth | ||
uses: docker/login-action@v2 | ||
with: | ||
username: 'oauth2accesstoken' | ||
password: ${{ steps.auth.outputs.access_token }} | ||
registry: asia-northeast1-docker.pkg.dev | ||
|
||
- name: Configure .env | ||
run: | | ||
echo "IS_PRODUCTION=true" >> .env | ||
echo "CONTEST_DATA_URL=${{ secrets.CONTEST_DATA_URL }}" >> .env | ||
|
||
- name: Download events.json from external URL | ||
run: | | ||
curl "${{ secrets.EVENTS_COMPLETE_URL }}" -o ./assets/data/events-detail.json | ||
curl "${{ secrets.EVENTS_SUMMARY_URL }}" -o ./assets/data/events.json | ||
|
||
- name: Build and push Docker image | ||
uses: docker/build-push-action@v5 | ||
with: | ||
push: true | ||
tags: asia-northeast1-docker.pkg.dev/ynufes-hp-cloudrun/release/tokiwa23:latest | ||
context: . | ||
file: ./cloudrun/Dockerfile | ||
|
||
- name: Download Cloud Run Service YAML | ||
run: | | ||
gcloud run services describe hp-main --format yaml --region asia-northeast1 > ./cloudrun/service-hp-main.yaml | ||
|
||
# replace github_sha field to latest commit sha. Changing spec.template is required to deploy new revision. | ||
# reference: https://cloud.google.com/run/docs/deploying?hl=ja#revision -- check yaml tab. | ||
- name: Change some property of service-hp-main.yaml | ||
run: | | ||
sed -i "s/github_sha: .*/github_sha: ${{ github.sha }}/g" ./cloudrun/service-hp-main.yaml | ||
|
||
- name: Deploy to Cloud Run | ||
id: deploy | ||
uses: google-github-actions/deploy-cloudrun@v2 | ||
with: | ||
region: "asia-northeast1" | ||
metadata: "./cloudrun/service-hp-main.yaml" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
name: Deploy to Cloud Run (Staging) | ||
on: | ||
push: | ||
branches: | ||
- main | ||
jobs: | ||
build-and-deploy: | ||
runs-on: ubuntu-latest | ||
permissions: | ||
contents: 'read' | ||
id-token: 'write' | ||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v4 | ||
|
||
- name: Set up Docker Buildx | ||
uses: docker/setup-buildx-action@v3 | ||
|
||
- name: Login to Google Cloud | ||
id: auth | ||
uses: google-github-actions/auth@v2 | ||
with: | ||
token_format: access_token | ||
workload_identity_provider: 'projects/292061085119/locations/global/workloadIdentityPools/github-pool/providers/provider-github' | ||
service_account: 'gh-actions@ynufes-hp-cloudrun.iam.gserviceaccount.com' | ||
|
||
- name: Set up Cloud SDK | ||
uses: 'google-github-actions/setup-gcloud@v2' | ||
with: | ||
version: '>= 363.0.0' | ||
|
||
- name: Configure .env | ||
run: | | ||
echo "IS_PRODUCTION=false" >> .env | ||
echo "CONTEST_DATA_URL=${{ secrets.CONTEST_DATA_URL_TEST }}" >> .env | ||
|
||
- name: Download events.json from external URL | ||
run: | | ||
curl "${{ secrets.EVENTS_COMPLETE_URL }}" -o ./assets/data/events-detail.json | ||
curl "${{ secrets.EVENTS_SUMMARY_URL }}" -o ./assets/data/events.json | ||
|
||
- name: Authorize Docker | ||
id: docker-auth | ||
uses: docker/login-action@v2 | ||
with: | ||
username: 'oauth2accesstoken' | ||
password: ${{ steps.auth.outputs.access_token }} | ||
registry: asia-northeast1-docker.pkg.dev | ||
|
||
- name: configure url, is_ | ||
|
||
|
||
- name: Build and push Docker image | ||
uses: docker/build-push-action@v5 | ||
with: | ||
push: true | ||
tags: asia-northeast1-docker.pkg.dev/ynufes-hp-cloudrun/staging/tokiwa23:latest | ||
context: . | ||
file: ./cloudrun/Dockerfile | ||
|
||
- name: Download Cloud Run Service YAML | ||
run: | | ||
gcloud run services describe hp-stg --format yaml --region asia-northeast1 > ./cloudrun/service-hp-stg.yaml | ||
|
||
# replace github_sha field to latest commit sha. Changing spec.template is required to deploy new revision. | ||
# reference: https://cloud.google.com/run/docs/deploying?hl=ja#revision -- check yaml tab. | ||
- name: Change some property of service-hp-stg.yaml | ||
run: | | ||
sed -i "s/github_sha: .*/github_sha: ${{ github.sha }}/g" ./cloudrun/service-hp-stg.yaml | ||
|
||
- name: Deploy to Cloud Run | ||
id: deploy | ||
uses: google-github-actions/deploy-cloudrun@v2 | ||
with: | ||
region: "asia-northeast1" | ||
metadata: "./cloudrun/service-hp-stg.yaml" |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
FROM node:20-slim as builder | ||
#nodeのイメージをベースにする | ||
|
||
ENV BASE_URL=/23/tokiwa/ | ||
|
||
WORKDIR /app | ||
#作業ディレクトリの指定 | ||
|
||
COPY ./ ./ | ||
#ynu-fes...の下を/appの下にコピー | ||
Comment on lines
+9
to
+10
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ensure that copying the entire project directory into the Docker image does not inadvertently include sensitive files or unnecessary files that could bloat the image size. It's good practice to use a |
||
|
||
RUN yarn install | ||
|
||
RUN yarn build | ||
Comment on lines
+12
to
+14
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The use of |
||
|
||
FROM node:20-slim as production | ||
|
||
WORKDIR /app | ||
|
||
COPY --from=builder /app/.output ./.output | ||
COPY --from=builder /app/.nuxt ./.nuxt | ||
#最小限のファイルをコピー | ||
|
||
ENV HOST=0.0.0.0 | ||
|
||
ENV BASE_URL=/23/tokiwa/ | ||
|
||
ENV PORT=8080 | ||
#環境変数の設定 | ||
|
||
CMD ["node" ,"./.output/server/index.mjs"] | ||
#--containerを作成するときに実行されるコマンド | ||
|
||
EXPOSE 8080 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The comment in line 2 is written in Japanese, which might not be universally understood by all team members or contributors. Consider translating comments into English to maintain consistency and ensure that the codebase is accessible to a wider audience.