-
Notifications
You must be signed in to change notification settings - Fork 0
147 lines (128 loc) · 4.55 KB
/
publish-laravel-to-registry.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: CI push Laravel App to registry.kolle.dev
on:
push:
branches:
- 'main'
- 'dev'
jobs:
laravel-test:
name: Laravel Testing (PHP ${{ matrix.php-versions }})
runs-on: ubuntu-latest
defaults:
run:
working-directory: ./laravel
env:
DB_DATABASE: laravel
DB_USERNAME: root
DB_PASSWORD: root
BROADCAST_DRIVER: log
KEYCLOAK_REALM_PUBLIC_KEY: 'MIIBI'
KEYCLOAK_ALLOWED_RESOURCES: account
KEYCLOAK_USER_PROVIDER_CREDENTIAL: email
KEYCLOAK_TOKEN_PRINCIPAL_ATTRIBUTE: email
strategy:
fail-fast: false
matrix:
php-versions: ['8.2', '8.3']
steps:
- name: Checkout
uses: actions/checkout@v4
# Docs: https://github.com/shivammathur/setup-php
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-versions }}
extensions: mbstring, dom, fileinfo, mysql
coverage: xdebug
# Local MySQL service in GitHub hosted environments is disabled by default.
# If you are using it instead of service containers, make sure you start it.
- name: Start mysql service
run: sudo systemctl start mysql.service
- name: Create default Database
run:
mysql -e 'CREATE DATABASE ${{ env.DB_DATABASE }};' -u${{
env.DB_USERNAME }} -p${{ env.DB_PASSWORD }}
- name: Get composer cache directory
id: composer-cache
run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
- name: Cache composer dependencies
uses: actions/cache@v4
with:
path: ${{ steps.composer-cache.outputs.dir }}
# Use composer.json for key, if composer.lock is not committed.
# key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: ${{ runner.os }}-composer-
- name: Install Composer dependencies
run: composer install --no-progress --prefer-dist --optimize-autoloader
- name: Prepare the application
run: |
php -r "file_exists('.env') || copy('.env.example', '.env');"
php artisan key:generate
# php artisan jwt:secret
- name: Clear Config
run: php artisan config:clear
- name: Run Migration
run: php artisan migrate -v
env:
DB_PORT: ${{ job.services.mysql.ports['3306'] }}
- name: Test with phpunit
run: vendor/bin/phpunit --coverage-text
env:
DB_PORT: ${{ job.services.mysql.ports['3306'] }}
docker:
name: Deployment via Docker-Image
needs: laravel-test
runs-on: ubuntu-latest
steps:
- name: Checkout Repository 🕹️
uses: actions/checkout@v4
- name: Nodejs Build Frontend 🚧
run: |
cd ./laravel
yarn install --frozen-lockfile
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to registry.kolle.dev Hub
uses: docker/login-action@v3
with:
registry: registry.kolle.dev
username: ${{ secrets.REGISTRY_USERNAME }}
password: ${{ secrets.REGISTRY_TOKEN }}
- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: registry.kolle.dev/cowiki-laravel
- name: Build 🚜
uses: docker/build-push-action@v5
with:
context: ./laravel
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
# - name: Deploy DEV 🚀
# if: ${{ github.ref == 'refs/heads/dev' }}
# uses: appleboy/[email protected]
# with:
# host: ${{ secrets.SSH_HOST }}
# username: ${{ secrets.SSH_USER }}
# key: ${{ secrets.SSH_KEY }}
# port: ${{ secrets.PORT }}
# script: |
# cd /opt/containers/cotest
# docker-compose pull cotest.api
# docker-compose up --force-recreate -d cotest.api
- name: Deploy MAIN 🚀
if: ${{ github.ref == 'refs/heads/main' }}
uses: appleboy/[email protected]
with:
host: ${{ secrets.SSH_HOST }}
username: ${{ secrets.SSH_USER }}
key: ${{ secrets.SSH_KEY }}
port: ${{ secrets.SSH_PORT }}
script: |
docker compose pull api
docker compose up --force-recreate -d api