-
Notifications
You must be signed in to change notification settings - Fork 0
94 lines (90 loc) · 2.89 KB
/
gss2022_backend_on_postgres_services.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
name: 幻水総選挙2022 バックエンド (Docker PostgreSQL)
on:
workflow_dispatch:
push:
branches:
- '**'
tags-ignore:
- 'v*.*.*'
env:
# TODO: Git のタグを取得して、イメージのタグにする
DOCKER_IMAGE: asia-northeast1-docker.pkg.dev/${{ secrets.CLOUD_RUN_PROJECT }}/cloud-run-source-deploy/gensosenkyo-2022-backend
GCP_REGION: ${{ secrets.CLOUD_RUN_REGION }}
GCP_AUTH_HOST: asia-northeast1-docker.pkg.dev
CLOUD_RUN_SERVICE_NAME: gensosenkyo-2022-backend
jobs:
gss2022_backend:
name: 幻水総選挙2022 バックエンド (Docker PostgreSQL)
runs-on: ubuntu-latest
strategy:
matrix:
node-version: ["18.x"]
ruby-version: ["3.1"]
services:
postgres:
image: postgres:15.1
ports:
- 5432:5432
env:
POSTGRES_USER: postgres_user
POSTGRES_PASSWORD: postgres_password
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
env:
CI: true
RAILS_ENV: test
PG_HOST_TEST: localhost
PG_PORT_TEST: 5432
PG_USERNAME_TEST: postgres_user
PG_PASSWORD_TEST: postgres_password
steps:
- name: コードをチェックアウトする
uses: actions/checkout@v3
- name: Ruby のセットアップを行う
uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby-version }}
bundler-cache: true
- name: $ bundle install を行う
uses: actions/cache@v3
with:
path: vendor/bundle
key: ${{ runner.os }}-gem-${{ hashFiles('**/Gemfile.lock') }}
restore-keys: |
${{ runner.os }}-gem-
- name: データベースをセットアップする
run: |
bin/rails db:prepare
- name: RSpec を実行する
run: |
bundle exec rspec
deploy_to_cloud_run:
needs: gss2022_backend
if: ${{ github.ref_name == 'main' }}
name: Cloud Run に production デプロイする
runs-on: ubuntu-latest
steps:
- name: ソースコードをチェックアウトする
uses: actions/checkout@v3
- name: GCP の認証を行う
uses: google-github-actions/auth@v1
with:
credentials_json: ${{ secrets.GCP_SERVICE_ACCOUNT_CREDENTIALS }}
- name: GCP の CLI の認証を行う
run: |
gcloud auth configure-docker ${{ env.GCP_AUTH_HOST }}
- name: Docker イメージ をビルドする
run: |
docker build -t ${{ env.DOCKER_IMAGE }} .
- name: Docker イメージ をプッシュする
run: |
docker push ${{ env.DOCKER_IMAGE }}
- name: Deploy to Cloud Run
uses: google-github-actions/deploy-cloudrun@v1
with:
service: ${{ env.CLOUD_RUN_SERVICE_NAME }}
image: ${{ env.DOCKER_IMAGE }}
region: ${{ env.GCP_REGION }}