-
Notifications
You must be signed in to change notification settings - Fork 0
146 lines (124 loc) · 4.3 KB
/
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
name: Quotly Build Pipeline
on:
workflow_dispatch:
push:
branches:
- main
pull_request:
branches:
- main
permissions: read-all
jobs:
run_integration_tests:
runs-on: self-hosted
env:
RUNNER_TOOL_CACHE: /toolcache
services:
database:
image: mariadb:10.6.19-ubi
ports:
- 3306:3306
env:
MYSQL_ROOT_PASSWORD: ${{ secrets.TEST_DATABASE_PASSWORD }}
MYSQL_DATABASE: ${{ vars.TEST_DATABASE_NAME }}
MYSQL_USER: ${{ vars.TEST_DATABASE_USERNAME }}
MYSQL_PASSWORD: ${{ secrets.TEST_DATABASE_PASSWORD }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Lint Dockerfile
uses: super-linter/[email protected]
env:
DEFAULT_BRANCH: origin/main
GITHUB_TOKEN: ${{ secrets.QUOTLY_TOKEN }}
FILTER_REGEX_INCLUDE: ^Dockerfile$
FILTER_REGEX_EXCLUDE: .*
VALIDATE_DOCKERFILE: true
VALIDATE_JSCPD: false
- name: Lint Java
uses: super-linter/[email protected]
env:
DEFAULT_BRANCH: origin/main
GITHUB_TOKEN: ${{ secrets.QUOTLY_TOKEN }}
FILTER_REGEX_INCLUDE: src/.*\.java$
VALIDATE_JAVA: true
- name: Set up JDK 17
uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: 17
cache: 'maven'
- name: Run backend tests
env:
DATABASE_URL: jdbc:mariadb://localhost:3306/${{ vars.TEST_DATABASE_NAME }}
DATABASE_USERNAME: ${{ vars.TEST_DATABASE_USERNAME }}
DATABASE_PASSWORD: ${{ secrets.TEST_DATABASE_PASSWORD }}
run: |
chmod +x mvnw
./mvnw test
build_and_push_docker_image:
runs-on: self-hosted
needs: run_integration_tests
env:
RUNNER_TOOL_CACHE: /toolcache
services:
docker:
image: docker:19.03.12
options: --privileged
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up JDK 17
uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: 17
cache: 'maven'
- name: Generate docker image tag
id: tag
run: |
REPOSITORY_OWNER=$(echo '${{ github.repository_owner }}' | tr '[:upper:]' '[:lower:]')
BRANCH_NAME=${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}
BRANCH_NAME=${BRANCH_NAME/'/#'/-}
BRANCH_NAME=${BRANCH_NAME//[^a-zA-Z0-9-]/}
if [ "$BRANCH_NAME" == "main" ]; then
DATE_TAG=$(date +'%Y.%m')
BUILD_NUMBER=$(echo $GITHUB_RUN_NUMBER)
DOCKER_IMAGE_TAG="${DATE_TAG}.${BUILD_NUMBER}"
DOCKER_IMAGE_NAME="ghcr.io/${REPOSITORY_OWNER}/quotly-release"
else
BUILD_NUMBER=$(echo $GITHUB_RUN_NUMBER)
DOCKER_IMAGE_TAG="${BRANCH_NAME}.${BUILD_NUMBER}"
DOCKER_IMAGE_NAME="ghcr.io/${REPOSITORY_OWNER}/quotly-staging"
fi
echo "DOCKER_IMAGE_TAG=$DOCKER_IMAGE_TAG" >> $GITHUB_ENV
echo "DOCKER_IMAGE_NAME=$DOCKER_IMAGE_NAME" >> $GITHUB_ENV
- name: Build backend
run: |
chmod +x mvnw
./mvnw clean
./mvnw versions:set -DnewVersion=${{ env.DOCKER_IMAGE_TAG }}
./mvnw package -Dquarkus.package.jar.type=uber-jar -DskipTests
- name: Build Docker image
run: |
TAG=${{ env.DOCKER_IMAGE_TAG }}
docker build -t quotly:$TAG .
- name: Login to Github Packages
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ vars.DOCKER_USERNAME }}
password: ${{ secrets.QUOTLY_TOKEN }}
- name: Push Docker image
run: |
DOCKER_IMAGE_TAG=${{ env.DOCKER_IMAGE_TAG }}
DOCKER_IMAGE_NAME=${{ env.DOCKER_IMAGE_NAME }}
docker tag quotly:$DOCKER_IMAGE_TAG $DOCKER_IMAGE_NAME:$DOCKER_IMAGE_TAG
docker push $DOCKER_IMAGE_NAME:$DOCKER_IMAGE_TAG
- name: Clean up old staging images
if: endsWith(env.DOCKER_IMAGE_NAME, 'staging')
run: |
chmod +x cleanup_docker_images.sh
./cleanup_docker_images.sh ${{ github.repository_owner }} quotly-staging ${{ secrets.QUOTLY_TOKEN }} 5