-
Notifications
You must be signed in to change notification settings - Fork 0
109 lines (105 loc) · 3.52 KB
/
api.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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
name: CI - API
on:
push:
branches: [ "main" ]
paths-ignore:
- '**/*.md'
- 'LICENSE'
- '**/.husky'
- 'sanity-cms/**'
- 'svelte-app/**'
concurrency:
group: api
cancel-in-progress: true
jobs:
test:
name: Test
environment: API
runs-on: ubuntu-latest
env:
ImageOS: ubuntu22
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Elixir
uses: erlef/setup-beam@v1
with:
elixir-version: 1.14.0
otp-version: 25
rebar3-version: 3.16
- name: Check formatting
run: (cd ./elixir-api && mix format --check-formatted)
- name: Restore dependencies cache
uses: actions/cache@v3
with:
path: elixir-api/deps
key: ${{ runner.os }}-mix-${{ hashFiles('**/mix.lock')}}
restore-keys: ${{ runner.os }}-mix-
- name: Install Dependencies
run: (cd ./elixir-api && mix deps.get --only test)
- name: Run tests
run: |
cd ./elixir-api &&\
touch ./.env &&\
echo "export PORT=4444" >> .env &&\
echo "export SANITY_TOKEN=${{ secrets.SANITY_TOKEN }}" >> .env &&\
echo "export SANITY_PROJECT_ID=${{ secrets.SANITY_PROJECT_ID }}" >> .env &&\
echo "export API_TOKEN=${{ secrets.DEV_API_TOKEN }}" >> .env &&\
make test
build:
name: Build and Push
environment: API
needs: [ test ]
runs-on: ubuntu-latest
strategy:
matrix:
environment: [ dev, prod ]
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Login to GCP Artifact Registry
uses: docker/login-action@v2
with:
registry: us-central1-docker.pkg.dev
username: _json_key
password: ${{ secrets.GCP_AR_PRIVATE_KEY }}
- name: Set API token
id: apitoken
run: |
if [[ "${{ matrix.environment }}" == "dev" ]]; then
echo "::set-output name=token::${{ secrets.DEV_API_TOKEN }}"
else
echo "::set-output name=token::${{ secrets.API_TOKEN }}"
fi
- name: Build and Push ${{ matrix.environment }} image
uses: docker/build-push-action@v2
with:
context: ./elixir-api
push: true
tags: |
us-central1-docker.pkg.dev/${{ secrets.GCP_PROJECT_ID }}/docker/hexerei-${{ matrix.environment }}:${{ github.sha }}
us-central1-docker.pkg.dev/${{ secrets.GCP_PROJECT_ID }}/docker/hexerei-${{ matrix.environment }}:latest
build-args: |
SANITY_TOKEN=${{ secrets.SANITY_TOKEN }}
SANITY_PROJECT_ID=${{ secrets.SANITY_PROJECT_ID }}
API_TOKEN=${{ steps.apitoken.outputs.token }}
ENV=${{ matrix.environment }}
GCLOUD_KEY=${{ secrets.GCLOUD_KEY }}
deploy:
name: Deploy
needs: [ build ]
runs-on: ubuntu-latest
strategy:
matrix:
environment: [ dev, prod ]
steps:
- name: Setup GCloud SDK
uses: google-github-actions/[email protected]
with:
service_account_key: ${{ secrets.GCP_CR_PRIVATE_KEY }}
project_id: ${{ secrets.GCP_PROJECT_ID }}
- name: Deploy ${{ matrix.environment }} to Cloud Run
run: |
gcloud run deploy hexerei-${{ matrix.environment }} --image us-central1-docker.pkg.dev/${{ secrets.GCP_PROJECT_ID }}/docker/hexerei-${{ matrix.environment }}:latest --region us-central1 --platform managed