Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci: Add native image generation #11

Open
wants to merge 32 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
7831d77
chore: update template version
cap-ang Jan 23, 2023
2bdc8b7
feat(deploy): add subscription key link for testing stages
cap-ang Jan 23, 2023
b677c75
fix(devops): adjust docker registry param
cap-ang Jan 25, 2023
e314191
fix(devops): adjust image repository variable
cap-ang Jan 25, 2023
de90360
ci: remove smoke test condition
cap-ang Jan 26, 2023
e2ac18b
ci(integration test): add framework type param
cap-ang Jan 26, 2023
5385a35
ci(integration test): fix headers
cap-ang Jan 27, 2023
d9a2e28
chore: mock default
cap-ang Jan 27, 2023
37091e0
fix((cd): update dockerfile
cap-ang Jan 27, 2023
582d47a
fix(cd): update dockerfile
cap-ang Jan 27, 2023
c336186
fix(cd): update dockerfile
cap-ang Jan 27, 2023
3bd44aa
fix(test): update integration test config
cap-ang Jan 27, 2023
29db5a9
fix(test): set integration test env config
cap-ang Jan 27, 2023
a195a8a
feat(test): add subkey as env variable
cap-ang Jan 27, 2023
6220bc5
ci(helm): setup node affinity
cap-ang Jan 27, 2023
ec46fb2
ci(test): fix params in axios functions
cap-ang Jan 27, 2023
3351e1c
fix(code-review): update container registry service connection var
cap-ang Feb 2, 2023
a2f88c1
fix(ci): adapt docker and test script
cap-ang Feb 2, 2023
dc3794d
fix: adjust smoke test config and functions
cap-ang Feb 8, 2023
12fa552
feat: add native and fix test
cap-ang Mar 17, 2023
c668a53
ci: add variables
cap-ang Mar 17, 2023
1f5eaea
ci: set pool image
cap-ang Mar 17, 2023
505aae5
ci: fix
cap-ang Mar 17, 2023
d448331
ci: fix
cap-ang Mar 17, 2023
90e5f7c
ci: update `Dockerfile` for native image
cap-ang Mar 20, 2023
5d630e4
chore: update template version
cap-ang Mar 20, 2023
2895c74
chore: update template version
cap-ang Mar 20, 2023
5b93599
ci: fix native dockerfile
cap-ang Mar 29, 2023
b11a742
ci: add health endpoints and update helm values
cap-ang Mar 29, 2023
65bbc63
test: add constant test type
cap-ang Mar 29, 2023
8613e81
Update constant test type
cap-ang Mar 29, 2023
21262f7
test: update maxVUs
cap-ang Mar 29, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .devops/code-review-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ stages:
- task: Docker@2
displayName: "Docker login"
inputs:
containerRegistry: "$(DEV_CONTAINER_REGISTRY_SERVICE_CONN)"
containerRegistry: "$(DEV_CONTAINER_REGISTRY)"
command: "login"

- task: Bash@3
Expand Down
21 changes: 14 additions & 7 deletions .devops/deploy-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,31 +31,38 @@ parameters:
values:
- False
- True
- name: "DOCKERFILE_NAME"
type: string
default: Dockerfile
values:
- Dockerfile
- Dockerfile-native
- name: TEST
displayName: Run integration/smoke tests
type: boolean
default: true

variables:
imageRepository: '$(IMAGE_REPOSITORY_NAME)'
imageRepository: '$(IMAGE_REPOSITORY)'
nameSpace: '$(K8S_NAMESPACE)'

${{ if eq(parameters['ENV'], 'dev') }}:
dockerRegistryServiceConnection: $(DEV_CONTAINER_REGISTRY_SERVICE_CONN)
dockerRegistryServiceConnection: $(DEV_CONTAINER_REGISTRY)
dockerRegistryFqdn: $(DEV_CONTAINER_NAMESPACE)
kubernetesServiceConnection: '$(DEV_KUBERNETES_SERVICE_CONN)'
poolImage: 'pagopa-dev-linux'
appInsightsServiceConn: "$(TF_APPINSIGHTS_SERVICE_CONN_DEV)"
appInsightsResourceId: "$(TF_APPINSIGHTS_RESOURCE_ID_DEV)"
pocReportingEnrollmentSubKey: "$(DEV_POC_ENROLLMENT_SUB_KEY)"
${{ if eq(parameters['ENV'], 'uat') }}:
dockerRegistryServiceConnection: $(UAT_CONTAINER_REGISTRY_SERVICE_CONN)
dockerRegistryServiceConnection: $(UAT_CONTAINER_REGISTRY)
dockerRegistryFqdn: $(UAT_CONTAINER_NAMESPACE)
kubernetesServiceConnection: '$(UAT_KUBERNETES_SERVICE_CONN)'
poolImage: 'pagopa-uat-linux'
appInsightsServiceConn: "$(TF_APPINSIGHTS_SERVICE_CONN_UAT)"
appInsightsResourceId: "$(TF_APPINSIGHTS_RESOURCE_ID_UAT)"
${{ if eq(parameters['ENV'], 'prod') }}:
dockerRegistryServiceConnection: $(PROD_CONTAINER_REGISTRY_SERVICE_CONN)
dockerRegistryServiceConnection: $(PROD_CONTAINER_REGISTRY)
dockerRegistryFqdn: $(PROD_CONTAINER_NAMESPACE)
kubernetesServiceConnection: '$(PROD_KUBERNETES_SERVICE_CONN)'
poolImage: 'pagopa-prod-linux'
Expand All @@ -74,7 +81,7 @@ resources:
- repository: pagopaCommons
type: github
name: pagopa/azure-pipeline-templates
ref: refs/tags/v2.10.1
ref: refs/tags/v3.9.0
endpoint: 'io-azure-devops-github-ro'

stages:
Expand Down Expand Up @@ -124,6 +131,7 @@ stages:
DOCKER_IMAGE_NAME: $(imageRepository)
DOCKER_IMAGE_TAG: $(current_version)
FORCE_REPLACE_DOCKER_IMAGE: ${{ parameters.FORCE_REPLACE_DOCKER_IMAGE }}
DOCKERFILE: ${{ parameters.DOCKERFILE_NAME }}

# Testing the docker image
- stage: Smoke_Test
Expand Down Expand Up @@ -158,11 +166,9 @@ stages:

# Deploy on K8s with Helm
- stage: Deploy
condition: not(failed('Smoke_Test'))
dependsOn:
- Release
- Build
- Smoke_Test
variables:
deploy_version: $[ stageDependencies.Release.make_release.outputs['current_version.value'] ]
jobs:
Expand Down Expand Up @@ -219,5 +225,6 @@ stages:
targetType: 'inline'
script: |
cd ./integration-test/src
export ORG_ENROLLMENT_SUBSCRIPTION_KEY=${{ variables.pocReportingEnrollmentSubKey }}
yarn install
yarn test:${{ parameters.ENV }}
35 changes: 21 additions & 14 deletions .devops/performance-test-pipelines.yml
Original file line number Diff line number Diff line change
@@ -1,47 +1,54 @@
# azure-pipelines.yml
trigger: none

pool:
name: performance-test-linux

parameters:
- name: "API_SUBSCRIPTION_KEY"
displayName: "API_SUBSCRIPTION_KEY"
type: string
- name: "ENVIRONMENT"
displayName: "Environment"
type: string
values:
- "dev"
- "uat"
- "prod"
- name: "TEST_TYPE"
displayName: "Test type"
type: string
values:
- "load"
- "spike"
- "stress"
- "soak"
- # TODO: add your values
- "constant"
- "smoke"
- name: "SCRIPT"
displayName: "Script name"
type: string
values:
- yourscriptname # TODO: add your script
- create_organization
- delete_organization
- get_organization
- get_organizations

variables:
${{ if eq(parameters['ENVIRONMENT'], 'dev') }}:
poolImage: 'pagopa-dev-loadtest-linux'
orgEnrollmentSubscriptionKey: '$(DEV_POC_ENROLLMENT_SUB_KEY)'
${{ if eq(parameters['ENVIRONMENT'], 'uat') }}:
poolImage: 'pagopa-uat-loadtest-linux'
orgEnrollmentSubscriptionKey: '$(UAT_POC_ENROLLMENT_SUB_KEY)'

pool:
name: $(poolImage)

steps:
- script: |
cd ./performance-tests/src
cd ./performance-test/src
docker pull grafana/k6
displayName: Pull k6 image

# TODO: add your env params
- script: |
cd ./performance-test/src
docker run \
-v ${PWD}:/script \
-e API_SUBSCRIPTION_KEY=${{ parameters.API_SUBSCRIPTION_KEY }} \
-e ORG_ENROLLMENT_SUBSCRIPTION_KEY=$(orgEnrollmentSubscriptionKey) \
-e VARS=${{ parameters.ENVIRONMENT }}.environment.json \
-e TEST_TYPE=./test-types/${{ parameters.TEST_TYPE }}.json \
grafana/k6 run /script/${{ parameters.SCRIPT }}.js \
grafana/k6 run /script/${{ parameters.SCRIPT }}.js
displayName: Run k6 ${{ parameters.SCRIPT }} on ${{ parameters.ENVIRONMENT }}
10 changes: 6 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@ COPY src /home/app/src
COPY pom.xml /home/app
COPY openapi.properties /home/app
RUN mvn -f /home/app/pom.xml clean package -Dmaven.test.skip=true
RUN mvn -f /home/app/pom.xml dependency:copy-dependencies

#
# Package stage
#
FROM adoptopenjdk/openjdk16:alpine
COPY --from=build /home/app/target/ReportingOrgsEnrollment-*.jar /usr/local/lib/app.jar
RUN true
FROM openjdk:17-alpine
WORKDIR /home/app
COPY --from=build /home/app/target/classes /home/app/classes
COPY --from=build /home/app/target/dependency/* /home/app/libs/
EXPOSE 8080
ENTRYPOINT ["java","-jar","/usr/local/lib/app.jar"]
ENTRYPOINT ["java", "-cp", "/home/app/libs/*:/home/app/classes/", "it.gov.pagopa.reportingorgsenrollment.Application"]
24 changes: 24 additions & 0 deletions Dockerfile-native
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
FROM maven:3.8.4-jdk-11-slim as buildtime
WORKDIR /build
COPY . .
RUN mvn clean package -Dmaven.test.skip=true
RUN mvn dependency:copy-dependencies

FROM ghcr.io/graalvm/native-image:ol7-java11-22.2.0 as builder
WORKDIR /home/app
COPY --from=buildtime build/target/classes /home/app/classes
COPY --from=buildtime build/target/dependency/* /home/app/libs/
COPY --from=buildtime build/native-image/* /home/app/classes/native-image/
ENV CLASS_NAME=it.gov.pagopa.reportingorgsenrollment.Application
ENV GRAALVM_ARGS="-H:+ReportExceptionStackTraces --initialize-at-build-time=org.codehaus.stax2.typed.Base64Variants -H:+AddAllCharsets -H:DynamicProxyConfigurationResources=./native-image/proxy-config.json -H:JNIConfigurationResources=./native-image/jni-config.json -H:ReflectionConfigurationResources=./native-image/reflect-config.json -H:ResourceConfigurationResources=./native-image/resource-config.json -H:SerializationConfigurationResources=./native-image/serialization-config.json --initialize-at-build-time=com.azure.data.tables.implementation.models"
ENV USE_NATIVE_IMAGE_JAVA_PLATFORM_MODULE_SYSTEM=false
RUN native-image ${GRAALVM_ARGS} -H:Class=${CLASS_NAME} -H:Name=application --no-fallback -cp "/home/app/libs/*:/home/app/classes/"

FROM frolvlad/alpine-glibc:alpine-3.12
ARG EXTRA_CMD
RUN if [[ -n "${EXTRA_CMD}" ]] ; then eval ${EXTRA_CMD} ; fi
COPY --from=builder /home/app/application /app/application

ARG PORT=8080
EXPOSE ${PORT}
ENTRYPOINT ["/app/application"]
13 changes: 3 additions & 10 deletions docker/config/.env
Original file line number Diff line number Diff line change
@@ -1,11 +1,4 @@
# TODO: put docker env vars here
ENV=docker
# to use azurite
#CONNECTION_STRING=UseDevelopmentStorage=true;DevelopmentStorageProxyUri=http://azure-storage

# to use cosmosDB
#COSMOS_URI=http://10.20.0.2:8081/
#COSMOS_KEY=C2y6yDjf5/R+ob0N8A7Cgv30VRDJIWEHLM+4QDU5DE2nQ9nDuVTqobD4b8mGGyPMbIZnqyMsEcaGQy67XIw/Jw==

ORGANIZATIONS_TABLE=organizations
STORAGE_PRIMARY_CONNECTION_KEY=<key>
# to use local azurite emulator
STORAGE_PRIMARY_CONNECTION_KEY=AccountName=devstoreaccount1;AccountKey=Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==;DefaultEndpointsProtocol=http;BlobEndpoint=http://host.docker.internal:10000/devstoreaccount1;QueueEndpoint=http://host.docker.internal:10001/devstoreaccount1;TableEndpoint=http://host.docker.internal:10002/devstoreaccount1;
ORGANIZATIONS_TABLE=organizations
20 changes: 10 additions & 10 deletions docker/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,16 @@ services:
# networks:
# afm_net:

# azure-storage:
# container_name: 'azure-storage'
# image: mcr.microsoft.com/azure-storage/azurite
# ports:
# - '10000:10000'
# - '10001:10001'
# - '10002:10002'
# networks:
# app_net:
# ipv4_address: 10.20.0.3
azure-storage:
container_name: 'azure-storage'
image: mcr.microsoft.com/azure-storage/azurite
ports:
- '10000:10000'
- '10001:10001'
- '10002:10002'
networks:
app_net:
ipv4_address: 10.20.0.3

# cosmosdb:
# container_name: 'cosmosdb'
Expand Down
22 changes: 15 additions & 7 deletions helm/values-dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ microservice-chart:
pullPolicy: Always
livenessProbe:
httpGet:
path: /info
path: /health/liveness
port: 8080
initialDelaySeconds: 90
failureThreshold: 6
periodSeconds: 10
readinessProbe:
httpGet:
path: /info
path: /health/readiness
port: 8080
initialDelaySeconds: 90
failureThreshold: 6
Expand All @@ -42,15 +42,15 @@ microservice-chart:
allowPrivilegeEscalation: false
resources:
requests:
memory: "384Mi"
cpu: "0.20"
memory: "256Mi"
cpu: "0.25"
limits:
memory: "512Mi"
cpu: "0.30"
cpu: "0.25"
autoscaling:
enable: true
minReplica: 1
maxReplica: 2
maxReplica: 3
pollingInterval: 10 # seconds
cooldownPeriod: 50 # seconds
triggers:
Expand All @@ -73,4 +73,12 @@ microservice-chart:
tenantId: "7788edaf-0346-4068-9d79-c868aed15b3d"
nodeSelector: {}
tolerations: []
affinity: {}
affinity:
nodeAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
nodeSelectorTerms:
- matchExpressions:
- key: node_type
operator: In
values:
- user
5 changes: 1 addition & 4 deletions integration-test/run_integration_test.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
# example: sh ./run_integration_test.sh <local|dev|uat|prod>
if [[ "$(pwd)" =~ .*"integration-test" ]]; then
cd ..
fi

# create containers
cd ./docker || exit
cd ../docker || exit
sh ./run_docker.sh "$1"

# waiting the containers
Expand Down
2 changes: 1 addition & 1 deletion integration-test/src/config/.env.dev
Original file line number Diff line number Diff line change
@@ -1 +1 @@
APP_HOST=https://host
REPORTING_ENROLLMENT_HOST=https://api.dev.platform.pagopa.it/shared/poc/reporting-orgs-enrollment/v1
2 changes: 1 addition & 1 deletion integration-test/src/config/.env.local
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
REPORTING_ENROLLMENT_HOST=http://localhost:8080

ORG_ENROLLMENT_SUBSCRIPTION_KEY=<subkey>
1 change: 0 additions & 1 deletion integration-test/src/config/.env.prod

This file was deleted.

1 change: 0 additions & 1 deletion integration-test/src/config/.env.uat

This file was deleted.

4 changes: 4 additions & 0 deletions integration-test/src/features/organizations.feature
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Feature: All about Organizations
Given an organization with id "UNKNOW"
When the organization "creates" enrollment
Then the organization gets the status code 201
Then the organization "deletes" enrollment

Scenario: An organization deletes an enrollment
Given a valid enrollment
Expand All @@ -17,11 +18,13 @@ Feature: All about Organizations
Given a valid enrollment
When the organization "gets" enrollment
Then the organization gets the status code 200
Then the organization "deletes" enrollment

Scenario: An organization gets all the enrollments
Given a valid enrollment
When the organization "gets all" enrollment
Then the organization gets the status code 200
Then the organization "deletes" enrollment

# 404

Expand All @@ -41,3 +44,4 @@ Feature: All about Organizations
Given a valid enrollment
When the organization "creates" enrollment
Then the organization gets the status code 409
When the organization "deletes" enrollment
2 changes: 0 additions & 2 deletions integration-test/src/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
"scripts": {
"test": "dotenv -e ./config/.env.local yarn cucumber",
"test:dev": "dotenv -e ./config/.env.dev yarn cucumber",
"test:uat": "dotenv -e ./config/.env.uat yarn cucumber",
"test:prod": "dotenv -e ./config/.env.prod yarn cucumber",
"cucumber": "npx cucumber-js --publish -r step_definitions"
},
"dependencies": {
Expand Down
Loading