Skip to content

Commit

Permalink
Feat/add release version on the check endpoint (#21)
Browse files Browse the repository at this point in the history
* feat: add release version on the check endpoint

* fix: set env var from maven version

* fix: release env var for test and prod

* fix: discard docker entrypoint changes
  • Loading branch information
Ricardo Campos authored and DerekRoberts committed May 14, 2024
1 parent 5deee8e commit fa33264
Show file tree
Hide file tree
Showing 9 changed files with 29 additions and 2 deletions.
6 changes: 6 additions & 0 deletions .github/openshift/deploy.backend.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ parameters:
- name: PROMOTE
description: Image (namespace/name:tag) to promote/import
value: bcgov/nr-backend-starting-api:prod-service-api
- name: NRBESTAPI_VERSION
description: Current service API release version
required: true
objects:
- apiVersion: v1
kind: ImageStream
Expand Down Expand Up @@ -83,6 +86,9 @@ objects:
- image: ${NAME}-${ZONE}-${COMPONENT}:${IMAGE_TAG}
imagePullPolicy: Always
name: ${NAME}
env:
- name: NRBESTAPI_VERSION
value: ${NRBESTAPI_VERSION}
ports:
- containerPort: 8090
protocol: TCP
Expand Down
10 changes: 10 additions & 0 deletions .github/workflows/merge-main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,10 @@ jobs:
ZONE: test
steps:
- uses: actions/checkout@v3
- name: Set NRBESTAPI_VERSION env
run: echo "NRBESTAPI_VERSION=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout)" >> $GITHUB_ENV
- name: Print NRBESTAPI_VERSION env
run: echo NRBESTAPI_VERSION:test-${{ env.NRBESTAPI_VERSION }}
- name: Deploy
run: |
# Login to OpenShift and select project
Expand All @@ -157,6 +161,7 @@ jobs:
#oc process -f .github/openshift/deploy.database.yml -p ZONE=${{ env.ZONE }} | oc create -f - || true
# Process and apply deployment templates
oc process -f .github/openshift/deploy.backend.yml -p ZONE=${{ env.ZONE }} \
-p NRBESTAPI_VERSION=test-${{ env.NRBESTAPI_VERSION }} \
-p PROMOTE=${{ github.repository }}:${{ env.ZONE }}-service-api | oc apply -f -
# Follow any active rollouts (see deploymentconfigs)
#oc rollout status dc/${{ env.NAME }}-${{ env.ZONE }}-database -w
Expand Down Expand Up @@ -281,6 +286,10 @@ jobs:
oc delete is/${{ env.NAME }}-${{ env.ZONE}}-${{ env.COMPONENT }} || true
- uses: actions/checkout@v3
- name: Set NRBESTAPI_VERSION env
run: echo "NRBESTAPI_VERSION=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout)" >> $GITHUB_ENV
- name: Print NRBESTAPI_VERSION env
run: echo NRBESTAPI_VERSION:prod-${{ env.NRBESTAPI_VERSION }}
- name: Deploy
run: |
# Login to OpenShift and select project
Expand All @@ -295,6 +304,7 @@ jobs:
# Process and apply deployment templates
#oc process -f .github/openshift/deploy.database.yml -p ZONE=${{ env.ZONE }} | oc apply -f -
oc process -f .github/openshift/deploy.backend.yml -p ZONE=${{ env.ZONE }} \
-p NRBESTAPI_VERSION=prod-${{ env.NRBESTAPI_VERSION }} \
-p PROMOTE=${{ github.repository }}:${{ env.PREV }}-service-api | oc apply -f -
# Follow any active rollouts (see deploymentconfigs)
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/pr-close.yml
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ jobs:
COMPONENT: backend
PREV: ${{ github.event.number }}
ZONE: test
NRBESTAPI_VERSION: test-${{ github.event.number }}
environment:
name: test
runs-on: ubuntu-22.04
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/pr-open.yml
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,7 @@ jobs:
env:
COMPONENT: service-api
ZONE: ${{ github.event.number }}
NRBESTAPI_VERSION: snapshot-${{ github.event.number }}
runs-on: ubuntu-latest
if: github.event_name == 'pull_request' && github.event.pull_request.base.ref == 'main'
needs:
Expand Down Expand Up @@ -326,6 +327,7 @@ jobs:
timeout-minutes: 15
env:
ZONE: ${{ github.event.number }}
NRBESTAPI_VERSION: snapshot-${{ github.event.number }}
steps:
- uses: actions/checkout@v3
- name: Deploy
Expand All @@ -347,6 +349,7 @@ jobs:
# Process and apply template
oc process -f .github/openshift/deploy.backend.yml -p ZONE=${{ env.ZONE }} \
-p NRBESTAPI_VERSION=${{ env.NRBESTAPI_VERSION }} \
-p PROMOTE=${{ github.repository }}:${{ env.ZONE }}-service-api | oc apply -f -
# Follow any active rollouts (see deploymentconfigs)
Expand Down
2 changes: 2 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ services:
backend:
container_name: service-api
image: service-api:latest
environment:
NRBESTAPI_VERSION: ${NRBESTAPI_VERSION}
hostname: service-api
ports:
- "8090:8090"
Expand Down
1 change: 0 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,6 @@
<configuration>
<skip>${checkstyle.skip}</skip>
<configLocation>.mvn/google_checks.xml</configLocation>
<encoding>UTF-8</encoding>
<consoleOutput>true</consoleOutput>
<failsOnError>true</failsOnError>
<linkXRef>false</linkXRef>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package ca.bc.gov.backendstartapi.endpoint;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
Expand All @@ -16,9 +17,12 @@
@RestController
public class CheckEndpoint {

@Value("${nrbestapi.version}")
private String nrbestapiVersion;

@GetMapping(value = "/check", produces = MediaType.APPLICATION_JSON_VALUE)
public Mono<ResponseEntity<? extends BaseResponse>> check() {
CheckVo check = CheckVo.builder().message("OK").build();
CheckVo check = CheckVo.builder().message("OK").release(nrbestapiVersion).build();
return Mono.just(ResponseEntity.status(HttpStatus.OK).body(check));
}
}
1 change: 1 addition & 0 deletions src/main/java/ca/bc/gov/backendstartapi/vo/CheckVo.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@
public class CheckVo implements BaseResponse {

private String message;
private String release;
}
1 change: 1 addition & 0 deletions src/main/resources/application.properties
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
server.port = 8090
nrbestapi.version = ${NRBESTAPI_VERSION}

0 comments on commit fa33264

Please sign in to comment.