-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
302 additions
and
56 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.nuxt | ||
.output | ||
node_modules |
This file contains 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
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 |
This file contains 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
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 }} |
This file contains 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
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" |
This file contains 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
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.
Oops, something went wrong.
This file contains 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
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の下にコピー | ||
|
||
RUN yarn install | ||
|
||
RUN yarn build | ||
|
||
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 |