-
Notifications
You must be signed in to change notification settings - Fork 0
121 lines (102 loc) · 3.47 KB
/
laravel.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
name: Laravel
on:
pull_request:
branches: [ "main" ]
push:
branches: [ "main" ]
env:
AWS_ACCOUNT_ID: ${{ secrets.AWS_ACCOUNT_ID }}
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
ECR_REGISTRY: ${{ secrets.ECR_REGISTRY }}
TASK_DEFINITION: ${{ vars.TASK_DEFINITION }}
ECS_CLUSTER: ${{ vars.ECS_CLUSTER }}
ECS_SERVICE: ${{ vars.ECS_SERVICE }}
PJ_PREFIX: ${{ vars.PJ_PREFIX }}
AWS_REGION: ${{ vars.AWS_REGION }}
permissions:
contents: read
jobs:
phpunit:
runs-on: ubuntu-latest
defaults:
run:
working-directory: ./src
services:
mysql:
image: mysql:8.0
env:
MYSQL_USER: user
MYSQL_PASSWORD: password
MYSQL_DATABASE: laravel
MYSQL_ROOT_PASSWORD: password
DB_PORT: ${{ job.services.mysql.ports[3306] }}
ports:
- 33306:3306
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3
steps:
- uses: actions/checkout@v1
with:
fetch-depth: 1
- name: Verify MySQL connection
run: |
mysql --host 127.0.0.1 --port ${{ job.services.mysql.ports['3306'] }} -u user -ppassword -e "SHOW DATABASES"
- name: Install dependencies
run: |
php --version
composer install -q --no-ansi --no-interaction --no-scripts --no-suggest --no-progress --prefer-dist
chmod -R 777 storage bootstrap/cache
- name: Boot Laravel application
run: |
php -r "file_exists('.env') || copy('.env.example', '.env');"
php artisan key:generate
php artisan --version
- name: Setup Node.js
uses: actions/setup-node@v2
with:
node-version: '18'
- name: Install Node.js dependencies
run: npm install
- name: Build Vite assets
run: npm run build
- name: Execute PHPUnit tests
env:
APP_ENV: testing
DB_CONNECTION: mysql
DB_HOST: 127.0.0.1
DB_DATABASE: laravel
DB_PORT: ${{ job.services.mysql.ports['3306'] }}
DB_USER: user
DB_PASSWORD: password
run: |
php artisan migrate
./vendor/bin/phpunit ./tests
building:
if: github.event_name == 'push'
needs: phpunit
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ env.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ env.AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ env.AWS_REGION }}
- name: Login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v1
- name: Build, tag, and push image to Amazon ECR
id: build-and-push-image
run: |
# Nginx
docker build --platform=linux/amd64 \
--build-arg AWS_ACCOUNT_ID=${{ env.AWS_ACCOUNT_ID }} \
--build-arg PJPrefix=${{ env.PJ_PREFIX }} \
-t ${{ env.ECR_REGISTRY }}:latest \
-f ./docker/build/nginx/Dockerfile .
docker push ${{ env.ECR_REGISTRY }}:latest
- name: Deploy Amazon ECS task definition
run:
aws ecs update-service --cluster ${{ env.ECS_CLUSTER }} --service ${{ env.ECS_SERVICE }} --task-definition ${{ env.TASK_DEFINITION }} --force-new-deployment