-
Notifications
You must be signed in to change notification settings - Fork 1
114 lines (99 loc) · 3.7 KB
/
build-package.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
name: build package
on:
workflow_call:
inputs:
ENVIRONMENT:
required: true
type: string
MICROSERVICE_NAME:
required: true
type: string
TOMCAT_PORT:
required: false
type: string
default: "8443"
TOMCAT_MAX_THREADS:
required: false
type: string
default: "150"
JAVA_VERSION:
required: false
type: string
default: "8"
TAG:
required: true
type: string
env:
DIRECTORY_SUFFIX: ${{ contains(inputs.MICROSERVICE_NAME, '-api') && '-rest-endpoints' || '' }}
NPMRC: ${{ secrets.NPMRC }}
jobs:
build:
runs-on: ubuntu-latest
environment:
name: ${{ inputs.ENVIRONMENT }}
permissions:
contents: read
packages: write
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Extract version number
id: getVersion
run: echo "VERSION_NUMBER=$(grep -Po -m 1 '(?<=<version>)[0-9\.]+(-SNAPSHOT)?' ${{ inputs.MICROSERVICE_NAME }}/pom.xml )" >> $GITHUB_OUTPUT
- name: Set up JDK
uses: actions/setup-java@v3
with:
java-version: ${{ inputs.JAVA_VERSION }}
distribution: 'adopt'
- name: Set up nodejs
uses: actions/setup-node@v4
with:
node-version: 16
#NOTE: necessary to build client-war
- name: Add .npmrc file
run: echo -e $NPMRC > ~/.npmrc
- name: Build with Maven and push to artifactory
run: |
export MAVEN_OPTS="-Xmx3072m -XX:MaxMetaspaceSize=512m"
export NODE_OPTIONS="--max-old-space-size=4096"
export RELEASE_URL=${{ vars.RELEASE_URL }}
export SNAPSHOT_URL=${{ vars.SNAPSHOT_URL }}
mvn --settings=settings.xml --batch-mode --update-snapshots -f ${{ inputs.MICROSERVICE_NAME }}/pom.xml -Drepo.login=${{ secrets.IDIR_AS_EMAIL }} -Drepo.password=${{ secrets.IDIR_PASSWORD }} -DopenshiftRepo.login=${{ secrets.OPENSHIFT_ACCOUNT }} -DopenshiftRepo.password=${{ secrets.OPENSHIFT_PASSWORD }} deploy
- name: Cache local Maven repository
uses: actions/cache@v2
with:
path: staging
key: ${{ runner.os }}-maven-${{ hashFiles('**war.xml') }}
restore-keys: |
${{ runner.os }}-maven-
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to GitHub Container Registry
uses: docker/login-action@v2
with:
registry: ${{ vars.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata (tags, labels) for Docker
id: meta_pr
uses: docker/metadata-action@v5
with:
images: ${{ vars.REGISTRY}}/${{ github.repository_owner }}/${{ inputs.MICROSERVICE_NAME }}
tags: |
type=schedule
type=raw,value=${{ github.base_ref }}
type=raw,value=latest
type=ref,event=tag
type=raw,value=${{ steps.getVersion.outputs.VERSION_NUMBER }}
type=raw,value=${{ inputs.TAG }}
${{ toJson(github.event.pull_request.number) == '{}' && format( 'type=raw,value=pr-{0}', github.event.pull_request.number) || '' }}
- name: Build and push
uses: docker/build-push-action@v5
with:
context: ./${{ inputs.MICROSERVICE_NAME }}
push: true
tags: ${{ steps.meta_pr.outputs.tags }}
labels: ${{ steps.meta_pr.outputs.labels }}
# NOTE: We store built images in ghcr.io, but use artifactory as a pull-through repository - artifacts.developer.gov.bc.ca/github-docker-remote/bcgov