-
Notifications
You must be signed in to change notification settings - Fork 5
147 lines (125 loc) · 4.57 KB
/
dev-build.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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
name : Setup, Build and Publish to Dev
on:
push:
branches: [development]
env:
PROJECT_ID: ${{ secrets.GKE_PROJECT }}
GKE_CLUSTER: nmrxiv-dev
GKE_ZONE: europe-west3-a
DEPLOYMENT_NAME: nmrxiv-nmrxiv-app
SCHEDULER_DEPLOYMENT_NAME: nmrxiv-scheduler
WORKER_DEPLOYMENT_NAME: nmrxiv-worker
DOCKER_HUB_USERNAME : ${{ secrets.DOCKER_HUB_USERNAME }}
DOCKER_HUB_PASSWORD : ${{ secrets.DOCKER_HUB_PASSWORD }}
REPOSITORY_NAME: nmrxiv
REPOSITORY_NAMESPACE: nfdi4chem
jobs:
php-unit-test:
name: Run tests
runs-on: ubuntu-latest
services:
postgres:
image: postgres:13
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: nmrxiv
ports:
- 5432:5432
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5
steps:
- uses: actions/checkout@v1
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.2'
extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, pdo_pgsql, bcmath, soap, intl, gd, exif, iconv
coverage: pcov
- name: Install composer dependencies
run: |
composer install --ignore-platform-reqs
- name: Prepare Laravel Application
run: |
php -r "file_exists('.env') || copy('.env.ci.test', '.env');"
echo AWS_ACCESS_KEY_ID=${{ secrets.AWS_ACCESS_KEY_ID_DEV }} >> .env
echo AWS_SECRET_ACCESS_KEY=${{ secrets.AWS_SECRET_ACCESS_KEY_DEV }} >> .env
echo MEILISEARCH_KEY=${{ secrets.MEILISEARCH_KEY_DEV }} >> .env
echo MEILISEARCH_PUBLICKEY=${{ secrets.MEILISEARCH_PUBLICKEY_DEV }} >> .env
echo TWITTER_CLIENT_ID=${{ secrets.TWITTER_CLIENT_ID_DEV }} >> .env
echo TWITTER_CLIENT_SECRET=${{ secrets.TWITTER_CLIENT_SECRET_DEV }} >> .env
echo GITHUB_CLIENT_ID=${{ secrets.CLIENT_ID_GITHUB_DEV }} >> .env
echo GITHUB_CLIENT_SECRET=${{ secrets.CLIENT_SECRET_GITHUB_DEV }} >> .env
php artisan key:generate
php artisan migrate --seed
- name: Install pcov
run: |
sudo apt-get update
sudo apt-get -y install php-pcov
- name: Install front-end dependencies
run: |
npm install
npm run build
- name: Run tests and collect coverage
run: vendor/bin/phpunit --coverage-clover coverage.xml
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_ORG_TOKEN }}
setup-build-publish-deploy:
name: Build & deploy to development
runs-on: ubuntu-latest
needs: php-unit-test
environment:
name: Dev
steps:
# Checkout code
- name: Checkout
uses: actions/checkout@v4
# Authenticate Github Actions to gcloud.
- name: Authenticate GitHub Actions
uses: 'google-github-actions/auth@v2'
with:
credentials_json: '${{ secrets.GKE_SA_KEY }}'
# Setup gcloud CLI
- name: Setup gcloud CLI
uses: google-github-actions/setup-gcloud@v2
# Get the GKE credentials
- name: Get GKE credentials
uses: google-github-actions/get-gke-credentials@v2
with:
cluster_name: ${{ env.GKE_CLUSTER }}
location: ${{ env.GKE_ZONE }}
# Login to Docker
- name: Log in to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ env.DOCKER_HUB_USERNAME }}
password: ${{ env.DOCKER_HUB_PASSWORD }}
# Build and push the app Docker image
- name: Build and push App Docker image
uses: docker/build-push-action@v5
with:
context: .
file: ./resources/ops/docker/app/app.dockerfile
push: true
build-args: |
RELEASE_VERSION=dev-app-latest
tags: ${{ env.REPOSITORY_NAMESPACE }}/${{ env.REPOSITORY_NAME }}:dev-app-latest
# Build and push the nginx Docker image
- name: Build and push Nginx Docker image
uses: docker/build-push-action@v5
with:
context: .
file: ./resources/ops/docker/nginx/nginx.dockerfile
push: true
build-args: |
RELEASE_VERSION=dev-nginx-latest
tags: ${{ env.REPOSITORY_NAMESPACE }}/${{ env.REPOSITORY_NAME }}:dev-nginx-latest
# Deploy the latest Docker image to the GKE cluster
- name: Deploy
run: |-
kubectl rollout restart deployment/$DEPLOYMENT_NAME
kubectl rollout restart deployment/$WORKER_DEPLOYMENT_NAME
kubectl rollout restart deployment/$SCHEDULER_DEPLOYMENT_NAME
kubectl rollout status deployment/$DEPLOYMENT_NAME --timeout=300s
kubectl get services -o wide