Skip to content

Commit d025c00

Browse files
authored
Bygger på github-actions (#178)
* Bygger på github-actions * Legger til settings.xml * Samme versjonsnr på docker og maven-artefakter * Endrer jenkinsfil til kun å deploye på master, gjør ingenting ellers. - Støtter da utrulling til q1,q0 og p av imager fra github packages
1 parent 79d1de6 commit d025c00

File tree

9 files changed

+162
-77
lines changed

9 files changed

+162
-77
lines changed

.deploy/p.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ metadata:
66
labels:
77
team: teamforeldrepenger
88
spec:
9-
image: repo.adeo.no:5443/fpabakus:RELEASE_VERSION # Required. Docker image.
9+
image: docker.pkg.github.com/navikt/fp-abakus/fpabakus:RELEASE_VERSION # Required. Docker image.
1010
port: 8080 # Required. The port number which is exposed by the container and should receive HTTP traffic.
1111
liveness: # HTTP endpoint that signals 200 OK when the application is running.
1212
path: /fpabakus/internal/isAlive

.deploy/q0.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ metadata:
66
labels:
77
team: teamforeldrepenger
88
spec:
9-
image: repo.adeo.no:5443/fpabakus:RELEASE_VERSION # Required. Docker image.
9+
image: docker.pkg.github.com/navikt/fp-abakus/fpabakus:RELEASE_VERSION # Required. Docker image.
1010
port: 8080 # Required. The port number which is exposed by the container and should receive HTTP traffic.
1111
liveness: # HTTP endpoint that signals 200 OK when the application is running.
1212
path: /fpabakus/internal/isAlive

.deploy/q1.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ metadata:
66
labels:
77
team: teamforeldrepenger
88
spec:
9-
image: repo.adeo.no:5443/fpabakus:RELEASE_VERSION # Required. Docker image.
9+
image: docker.pkg.github.com/navikt/fp-abakus/fpabakus:RELEASE_VERSION # Required. Docker image.
1010
port: 8080 # Required. The port number which is exposed by the container and should receive HTTP traffic.
1111
liveness: # HTTP endpoint that signals 200 OK when the application is running.
1212
path: /fpabakus/internal/isAlive

.deploy/t4.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ metadata:
66
labels:
77
team: teamforeldrepenger
88
spec:
9-
image: repo.adeo.no:5443/fpabakus:RELEASE_VERSION # Required. Docker image.
9+
image: {{ image }}:{{ tag }} # Required. Docker image.
1010
port: 8080 # Required. The port number which is exposed by the container and should receive HTTP traffic.
1111
liveness: # HTTP endpoint that signals 200 OK when the application is running.
1212
path: /fpabakus/internal/isAlive

.github/workflows/build-pr.yml

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
name: Bygg pull request
2+
3+
on: [pull_request]
4+
5+
jobs:
6+
build:
7+
8+
runs-on: ubuntu-latest
9+
10+
services:
11+
postgres:
12+
image: postgres:11.5
13+
env:
14+
POSTGRES_USER: fpabakus_unit
15+
POSTGRES_PASSWORD: fpabakus_unit
16+
POSTGRES_DB: fpabakus_unit
17+
ports:
18+
- 5432:5432
19+
# needed because the postgres container does not provide a healthcheck
20+
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5
21+
22+
steps:
23+
- uses: actions/checkout@v1
24+
- uses: actions/cache@v1
25+
with:
26+
path: ~/.m2/repository
27+
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
28+
restore-keys: |
29+
${{ runner.os }}-maven-
30+
- uses: actions/setup-java@v1
31+
with:
32+
java-version: 1.11
33+
- name: Build
34+
shell: bash
35+
run: |
36+
echo "Building $(echo $GITHUB_SHA | cut -c1-7)"
37+
mvn package --batch-mode --settings ./.m2/settings.xml --file pom.xml -Dchangelist= -Dsha1=-$(git log -1 --pretty='%ad' --date=format:'%Y%m%d%H%M%S')-$(echo $GITHUB_SHA | cut -c1-7)
38+
env:
39+
GITHUB_USERNAME: x-access-token
40+
GITHUB_PASSWORD: ${{ secrets.GITHUB_ACCESS_TOKEN }}
41+
DATASOURCE_HOST: localhost
42+
DATASOURCE_PORT: ${{ job.services.postgres.ports[5432] }} # get randomly assigned published port

.github/workflows/build.yml

+69
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
name: Bygg og deploy
2+
3+
on:
4+
push:
5+
branches:
6+
- master # Push events on master branch
7+
8+
jobs:
9+
build:
10+
11+
runs-on: ubuntu-latest
12+
13+
services:
14+
postgres:
15+
image: postgres:11.5
16+
env:
17+
POSTGRES_USER: fpabakus_unit
18+
POSTGRES_PASSWORD: fpabakus_unit
19+
POSTGRES_DB: fpabakus_unit
20+
ports:
21+
- 5432:5432
22+
# needed because the postgres container does not provide a healthcheck
23+
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5
24+
25+
steps:
26+
- uses: actions/checkout@v1
27+
- uses: actions/cache@v1
28+
with:
29+
path: ~/.m2/repository
30+
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
31+
restore-keys: |
32+
${{ runner.os }}-maven-
33+
- uses: actions/setup-java@v1
34+
with:
35+
java-version: 1.11
36+
- name: Build artifacts & deploy
37+
shell: bash
38+
run: |
39+
echo "Building artifacts $(echo $GITHUB_SHA | cut -c1-7)"
40+
mvn clean deploy --batch-mode --settings ./.m2/settings.xml -Dmaven.wagon.http.pool=false --file pom.xml -Dchangelist= -Dsha1=-$(git log -1 --pretty='%ad' --date=format:'%Y%m%d%H%M%S')-$(echo $GITHUB_SHA | cut -c1-7) -Dfile.encoding=UTF-8 -DinstallAtEnd=true -DdeployAtEnd=true
41+
echo "Deployed artifacts"
42+
env:
43+
GITHUB_USERNAME: x-access-token
44+
GITHUB_PASSWORD: ${{ secrets.GITHUB_ACCESS_TOKEN }}
45+
DATASOURCE_HOST: localhost
46+
DATASOURCE_PORT: ${{ job.services.postgres.ports[5432] }} # get randomly assigned published port
47+
48+
- name: Sette Docker- navn og tag
49+
env:
50+
DOCKER_IMAGE: docker.pkg.github.com/${{ github.repository }}/fpabakus
51+
run: |
52+
echo $DOCKER_IMAGE > .docker_image
53+
echo "$(git log -1 --pretty='%ad' --date=format:'%Y%m%d%H%M%S')-$(echo $GITHUB_SHA | cut -c1-7)" > .docker_tag
54+
- name: Bygge Docker image
55+
run: docker build . --pull -t $(cat .docker_image):$(cat .docker_tag)
56+
- name: Laste opp Docker image
57+
run: |
58+
echo "$GITHUB_ACCESS_TOKEN" | docker login --username "x-access-token" --password-stdin https://docker.pkg.github.com
59+
docker push $(cat .docker_image):$(cat .docker_tag)
60+
env:
61+
GITHUB_ACCESS_TOKEN: ${{ secrets.GITHUB_ACCESS_TOKEN }}
62+
- name: Deploye til dev
63+
uses: navikt/deployment-cli/[email protected]
64+
env:
65+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
66+
with:
67+
cluster: dev-fss
68+
team: teamforeldrepenger
69+
resources: .deploy/t4.yaml

.m2/settings.xml

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?xml version='1.0' encoding='UTF-8' ?>
2+
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0
5+
http://maven.apache.org/xsd/settings-1.0.0.xsd">
6+
7+
<activeProfiles>
8+
<activeProfile>github</activeProfile>
9+
</activeProfiles>
10+
11+
<profiles>
12+
<profile>
13+
<id>github</id>
14+
<repositories>
15+
<repository>
16+
<id>central</id>
17+
<url>https://repo1.maven.org/maven2</url>
18+
<releases>
19+
<enabled>true</enabled>
20+
</releases>
21+
<snapshots>
22+
<enabled>true</enabled>
23+
</snapshots>
24+
</repository>
25+
<repository>
26+
<id>github</id>
27+
<name>GitHub Apache Maven Packages</name>
28+
<url>https://maven.pkg.github.com/navikt/fp-felles/</url>
29+
</repository>
30+
</repositories>
31+
</profile>
32+
</profiles>
33+
34+
35+
<servers>
36+
<server>
37+
<id>github</id>
38+
<username>${env.GITHUB_USERNAME}</username>
39+
<password>${env.GITHUB_PASSWORD}</password>
40+
</server>
41+
</servers>
42+
</settings>

Jenkinsfile

+3-71
Original file line numberDiff line numberDiff line change
@@ -62,95 +62,27 @@ pipeline {
6262

6363
if (env.BRANCH_NAME == 'master') {
6464
sh "git fetch"
65-
latestTag = sh(script: "git describe --tags", returnStdout: true)?.trim()
66-
latestTagCommitHash = sh(script: "git describe \$(git rev-list --tags --max-count=1) | sed 's/.*\\_//'", returnStdout: true)?.trim()
67-
68-
echo "GIT_COMMIT_HASH: $GIT_COMMIT_HASH, latestTagCommitHash: $latestTagCommitHash"
6965
def deployVersjon = params.deployVersjon
7066
def deployGivenVersion = (deployVersjon != null && !"".equals(deployVersjon))
71-
skipBuild = deployGivenVersion || GIT_COMMIT_HASH.equals(latestTagCommitHash)
67+
skipBuild = deployGivenVersion
7268
if (skipBuild && deployGivenVersion) {
7369
version = deployVersjon
7470
echo "Version supplied, skipping build and deploy declared version={$version}."
75-
} else if (skipBuild) {
76-
version = latestTag
77-
echo "No change detected in sourcecode, skipping build and deploy existing tag={$latestTag}."
7871
}
7972
currentBuild.displayName = version
8073
}
8174
}
8275
}
8376
}
8477

85-
stage('Set version') {
86-
steps {
87-
sh "mvn --version"
88-
//sh "echo $version > VERSION"
89-
}
90-
}
91-
92-
stage('Build') {
93-
when {
94-
expression { return !skipBuild }
95-
}
96-
steps {
97-
script {
98-
echo "Building $version"
99-
currentBuild.displayName = version + "*"
100-
fpgithub.updateBuildStatus(githubRepoName, "pending", GIT_COMMIT_HASH_FULL)
101-
102-
withMaven(mavenSettingsConfig: 'navMavenSettingsPkg', maven: 'maven-3.6.2', mavenLocalRepo: '.repository') {
103-
buildEnvironment = new buildEnvironment()
104-
buildEnvironment.setEnv()
105-
if (mvn.javaVersion() != null) {
106-
buildEnvironment.overrideJDK(mvn.javaVersion())
107-
}
108-
109-
envs = sh(returnStdout: true, script: 'env | sort -h').trim()
110-
echo("envs: " + envs)
111-
112-
sh "mvn -B -e -U -Dfile.encoding=UTF-8 -DinstallAtEnd=true -DdeployAtEnd=true -Dsha1= -Dchangelist= -Drevision=$version clean deploy"
113-
sh "docker build --pull -t $DOCKERREGISTRY/$ARTIFACTID:$version ."
114-
withCredentials([[$class : 'UsernamePasswordMultiBinding',
115-
credentialsId : 'nexusUser',
116-
usernameVariable: 'NEXUS_USERNAME',
117-
passwordVariable: 'NEXUS_PASSWORD']]) {
118-
sh "docker login -u ${env.NEXUS_USERNAME} -p ${env.NEXUS_PASSWORD} ${DOCKERREGISTRY} && docker push ${DOCKERREGISTRY}/${ARTIFACTID}:${version}"
119-
}
120-
}
121-
}
122-
}
123-
post {
124-
success {
125-
script {
126-
fpgithub.updateBuildStatus(githubRepoName, "success", GIT_COMMIT_HASH_FULL)
127-
}
128-
}
129-
failure {
130-
script {
131-
fpgithub.updateBuildStatus(githubRepoName, "failure", GIT_COMMIT_HASH_FULL)
132-
}
133-
}
134-
}
135-
}
136-
137-
stage('Tag master') {
138-
when {
139-
branch 'master'
140-
expression { return !skipBuild }
141-
}
142-
steps {
143-
sh "git tag $version -m $version"
144-
sh "git push origin --tag"
145-
}
146-
}
14778
stage('Deploy') {
14879
when {
14980
branch 'master'
81+
expression { return (deployVersjon != null && !"".equals(deployVersjon)) }
15082
}
15183
steps {
15284
script {
153-
def value = "s/RELEASE_VERSION/${version}/g"
85+
def value = "s/RELEASE_VERSION/${params.deployVersjon}/g"
15486
sh "sed \'$value\' .deploy/${MILJO}.yaml > nais.yaml"
15587

15688
def naisNamespace

web/src/main/java/no/nav/foreldrepenger/abakus/app/konfig/ApplicationConfig.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
import javax.ws.rs.ApplicationPath;
1010
import javax.ws.rs.core.Application;
1111

12+
import io.swagger.v3.jaxrs2.integration.JaxrsOpenApiContextBuilder;
1213
import io.swagger.v3.jaxrs2.integration.resources.OpenApiResource;
13-
import io.swagger.v3.oas.integration.GenericOpenApiContextBuilder;
1414
import io.swagger.v3.oas.integration.OpenApiConfigurationException;
1515
import io.swagger.v3.oas.integration.SwaggerConfiguration;
1616
import io.swagger.v3.oas.models.OpenAPI;
@@ -53,7 +53,7 @@ public ApplicationConfig() {
5353
.collect(Collectors.toSet()));
5454

5555
try {
56-
new GenericOpenApiContextBuilder()
56+
new JaxrsOpenApiContextBuilder<>()
5757
.openApiConfiguration(oasConfig)
5858
.buildContext(true)
5959
.read();

0 commit comments

Comments
 (0)