-
Notifications
You must be signed in to change notification settings - Fork 0
126 lines (103 loc) · 3.21 KB
/
build-and-deploy.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
name: Test, Build and Deploy
on:
push:
branches:
- main
- dev
- test
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up PHP
uses: shivammathur/setup-php@v2
with:
php-version: "8.2"
extensions: mbstring, pdo_mysql, pdo_pgsql, pcntl, exif, bcmath, gd, intl, zip
ini-values: |
memory_limit=-1
coverage: none
- name: Install system dependencies
run: |
sudo apt-get update && sudo apt-get install -y \
libpq-dev \
libpng-dev \
libonig-dev \
libxml2-dev \
libzip-dev \
libicu-dev \
zip \
unzip \
git \
curl \
postgresql-client \
nodejs \
npm
- name: Cache dependencies
uses: actions/cache@v4
with:
path: vendor
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: ${{ runner.os }}-composer-
- name: Install Composer dependencies
run: composer install --prefer-dist --no-progress --no-suggest --no-interaction
- name: Install Node.js dependencies and build assets
run: |
npm install
npm run build
- name: Set up Laravel environment
run: |
cp .env.example .env
php artisan key:generate
- name: Run tests
run: vendor/bin/pest
build:
runs-on: ubuntu-latest
needs: test
steps:
- uses: actions/checkout@v4
- name: Login to Container Registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
- name: Build and push
uses: docker/build-push-action@v5
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
outputs:
image_tag: ${{ steps.meta.outputs.tags }}
deploy:
runs-on: ubuntu-latest
needs: build
environment: ${{ github.ref == 'refs/heads/main' && 'prod' || (github.ref == 'refs/heads/dev' && 'dev') || github.ref == 'refs/heads/test' && 'test' }}
steps:
- uses: actions/checkout@v4
- name: Install oc CLI
uses: redhat-actions/oc-installer@v1
- name: Authenticate and set context for OpenShift
uses: redhat-actions/oc-login@v1
with:
openshift_server_url: ${{ vars.OPENSHIFT_SERVER }}
namespace: ${{ vars.OPENSHIFT_NAMESPACE }}
openshift_token: ${{ secrets.OPENSHIFT_TOKEN }}
insecure_skip_tls_verify: true
- name: Run Helm upgrade
run: |
helm upgrade --install klamm-app ./helm --set image.tag=${{ needs.build.outputs.image_tag }}
- name: Trigger OpenShift Rollout
run: |
oc rollout restart deployment/klamm-app