diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 00000000..ef69c707 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,2 @@ +# ignore the target directory +target/ \ No newline at end of file diff --git a/.env b/.env new file mode 100644 index 00000000..32c48d17 --- /dev/null +++ b/.env @@ -0,0 +1,29 @@ + +#Deployment configuration +ENVIRONMENT=prod + +# Application default configuration +httpport=8080 +httpsport=8443 +appname=tdpcbpmqreader +appversion=0.2 +apphttpport=80 +apphttpsport=443 + +# Bicep Parameters +targetPort=9080 +maxReplicas=20 +minReplicas=4 +cpuCore=0.5 +memorySize=1 + +# Change this for your deployment +aca_volume_mountPath=opt/app +aca_volumes_name=azure-files-volume + +# Azure Container Apps Storage configuration +# Create a file storage for the storage account +acenv_fileshare_resource_group=share_rg +acenv_storage_account_name=jrlmsftstorage +acenv_fileshareName=acafileshare +acenv_volumes_storagename=filestorage diff --git a/.env.example b/.env.example new file mode 100644 index 00000000..23f869f8 --- /dev/null +++ b/.env.example @@ -0,0 +1,43 @@ +#Deployment configuration +ENVIRONMENT=dev +# Application default configuration +httpport= 8080 +httpsport= 8433 +appname= APP_NAME_PLACEHOLDER +appversion= APP_VERSION_PLACEHOLDER +apphttpport= 80 +apphttpsport= 443 +apploglevel= APP_LOG_LEVEL_PLACEHOLDER + +# Image configuration +repository= REPOSITORY_PLACEHOLDER +imageName= IMAGE_NAME_PLACEHOLDER +imageTag= IMAGE_TAG_PLACEHOLDER +image= IMAGE_PLACEHOLDER + +# Azure Subscription configuration +AzureSubscriptionId= SUBSCRIPTION_ID_PLACEHOLDER +location= LOCATION_PLACEHOLDER +CreateResourceGroup=FALSE +ResourceGroupName= RESOURCE_GROUP_NAME_PLACEHOLDER +# Create json with dummy user names and passwords +# echo '{"username":"USERNAME_PLACEHOLDER","password":"PASSWORD_PLACEHOLDER"}' > ./azure_credentials.json +json={"username":"USERNAME_PLACEHOLDER","password":"PASSWORD_PLACEHOLDER"} + +# Bicep Parameters +name= NAME_PLACEHOLDER +containerRegistry= CONTAINER_REGISTRY_PLACEHOLDER +containerImage= CONTAINER_IMAGE_PLACEHOLDER +targetPort= TARGET_PORT_PLACEHOLDER +maxReplicas= MAX_REPLICAS_PLACEHOLDER +minReplicas= MIN_REPLICAS_PLACEHOLDER +cpuCore= CPU_CORE_PLACEHOLDER +memorySize= MEMORY_SIZE_PLACEHOLDER +aca_volume_mountPath= ACA_VOLUME_MOUNT_PATH_PLACEHOLDER + +# Azure Container Apps Storage configuration +aca_fileshareName= ACA_FILE_SHARE_NAME_PLACEHOLDER +azure_storage_name= AZURE_STORAGE_NAME_PLACEHOLDER +aca_volumes_name= azure-files-volume # do not change +aca_volumes_storagename= filestorage # do not change +fileshare_resource_group= FILE_SHARE_RESOURCE_GROUP_PLACEHOLDER \ No newline at end of file diff --git a/.github/workflows/workflow.yaml b/.github/workflows/workflow.yaml new file mode 100644 index 00000000..51384570 --- /dev/null +++ b/.github/workflows/workflow.yaml @@ -0,0 +1,69 @@ +# File: .github/workflows/workflow.yml + +on: [push] +# on: [workflow_dispatch] + +name: Deploy the petstore app using Github Actions +permissions: + id-token: write + contents: read +env: + branch: 'buildtoacr_01082024' + reponame: 'swagger-petstore' + subscriptionId: ${{ secrets.AZURE_SUBSCRIPTION_ID }} + containerImage: ${{secrets.ACRNAME}}.azurecr.io/${{env.reponame}}:latest + containerRegistryName: ${{secrets.ACRNAME}} + registryserver: ${{secrets.ACRNAME}}.azurecr.io + createResourceGroup: false + name: "petstoredev2" +jobs: + + build-and-deploy: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + # with: + # ref: ${{ env.branch}} + + - name: Login to Azure Container Registry + uses: Azure/docker-login@v1 + with: + # Container registry username + username: ${{ secrets.ACR_USERNAME }} + # Container registry password + password: ${{ secrets.ACR_PASSWORD }} + # Container registry server url + login-server: ${{ secrets.ACRNAME }}.azurecr.io + + + # Add id token and contents to the permissions + - name: Azure login + uses: azure/login@v1 + with: + client-id: ${{ secrets.AZURE_CLIENT_ID }} + tenant-id: ${{ secrets.AZURE_TENANT_ID }} + subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }} + + - name: Build the Docker image + run: + az acr build --registry ${{secrets.ACRNAME}} --image swagger-petstore:$(date +'%Y-%m-%d')_$GITHUB_RUN_NUMBER -t ${{secrets.ACRNAME}}.azurecr.io/swagger-petstore:latest --file Dockerfile .; + + + + - name: Deploy Azure Container App + shell: pwsh + run: | + ./deploy_infra.ps1 + # Deploy K8s manifest + # - name: Deploy K8s manifest + # uses: Azure/k8s-deploy@v4 + # with: + # azureCredentials: ${{ secrets.AZURE_CREDENTIALS }} + # namespace: default + # manifests: | + # k8s/deployment.yaml + # k8s/service.yaml + # k8s/ingress.yaml + # imagePullSecrets: ${{ secrets.ACRNAME }} + \ No newline at end of file diff --git a/.gitignore b/.gitignore index 313c82f0..868d5260 100644 --- a/.gitignore +++ b/.gitignore @@ -10,3 +10,13 @@ target atlassian-ide-plugin.xml *.iml .java-version +.DS_Store +# ignore .env file +# .env +# ignore .vscode folder +.vscode/ +compose.log +svcprincipal_create.md +draft.md +creds.json +``` \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 00000000..b84f89c3 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,4 @@ +{ + "java.configuration.updateBuildConfiguration": "interactive", + "java.compile.nullAnalysis.mode": "automatic" +} \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 4ed8e816..c28c5af5 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,11 +1,26 @@ -FROM openjdk:8-jre-alpine +# Build stage +FROM maven:3.8.6-openjdk-11-slim AS build + +RUN apt-get update && apt-get install -y git +# RUN git clone +RUN mvn -version +WORKDIR /home/app/ +COPY src ./src/ +COPY pom.xml ./pom.xml +RUN ls -ltr +RUN pwd +RUN ls -ltr ./src/ +RUN mvn -f pom.xml clean install -DskipTests=true + +# FROM openjdk:8-jre-alpine +FROM eclipse-temurin:11-jre-alpine WORKDIR /swagger-petstore -COPY target/lib/jetty-runner.jar /swagger-petstore/jetty-runner.jar -COPY target/*.war /swagger-petstore/server.war -COPY src/main/resources/openapi.yaml /swagger-petstore/openapi.yaml -COPY inflector.yaml /swagger-petstore/ +COPY --chown=1001:0 --from=build /home/app/target/lib/jetty-runner.jar /swagger-petstore/jetty-runner.jar +COPY --chown=1001:0 --from=build /home/app/target/*.war /swagger-petstore/server.war +COPY --chown=1001:0 src/main/resources/openapi.yaml /swagger-petstore/openapi.yaml +COPY --chown=1001:0 inflector.yaml /swagger-petstore/ EXPOSE 8080 diff --git a/archive/deploy_infra_archive_02142023.ps1 b/archive/deploy_infra_archive_02142023.ps1 new file mode 100644 index 00000000..ce788e88 --- /dev/null +++ b/archive/deploy_infra_archive_02142023.ps1 @@ -0,0 +1,118 @@ +param( + [string]$templateFile=".\infra\main.bicep", + # read pararmeters from .env file + $envParameters = $(Get-Content .\.env | ConvertFrom-StringData), + # get name from parameters + [string]$name=$envParameters.name, + [string]$location=$envParameters.location, + # get createResourceGroup from parameters + [string]$createResourceGroup=$envParameters.createResourceGroup, + + [string]$subscriptionId=$env:subscriptionId, + + # get resource group name from parameters + # if createResourceGroup is false, use the resource group name from parameters else + # use the name "name-rg" + [string]$resourceGroupName=$(if ($createResourceGroup -eq "false") { + $envParameters.resourceGroup} else { + "$name-rg"}), + [string]$containerRegistryName=$envParameters.containerRegistryName, + + # Image configuration + # [string]$registryserver=$envParameters.registryserver, + # [string]$repository=$envParameters.repository, + # [string]$imagetag=$envParameters.deploymentImageTag, + # Container image in the format of /: + # [string]$containerImage="$($registryserver)/$($repository):$($imagetag)", + + # New: Get Container image from github workflow environment + [string]$containerImage=$env:registryserver, + + #Azure Container Environment Related values + [string]$acenv_fileshare_resource_group=$envParameters.acenv_fileshare_resource_group, + [string]$acenv_storage_account_name=$envParameters.acenv_storage_account_name, + [string]$acenv_fileshareName=$envParameters.acenv_fileshareName, + [string]$acenv_volumes_storagename=$envParameters.acenv_volumes_storagename, + + #Azure Container Apps Related values + [string]$aca_volumes_name=$envParameters.aca_volumes_name, + [string]$aca_volume_mountPath=$envParameters.aca_volume_mountPath , + [string]$aca_targetPort=$envParameters.targetPort, + [string]$aca_maxReplicas=$envParameters.maxReplicas, + [string]$aca_minReplicas=$envParameters.minReplicas + ) + +# set default subscription +az account set --subscription $subscriptionId + +#Write Container registry +write-host "Container Registry: $containerRegistryName" + +# Container registry username +[string]$acrUsername=$(az acr credential show -n $containerRegistryName --query username -o tsv) + + +# # Container registry password +# # TODO: use SecureString +# # TODO: use keyvault to store password +[string]$acrPassword=$(az acr credential show -n $containerRegistryName --query "passwords[0].value" -o tsv) + +# # Create a resource group with azure cli +# Create a resource group if $createResourceGroup is true +write-host "Create Resource Group: $createResourceGroup" + +if ($createResourceGroup -eq "true") { + Write-Host "Creating resource group $resourceGroupName" + az group create --name $resourceGroupName --location $location +} +Write-Host "Resource Group Name: $resourceGroupName" +# Test message +# Write-Host "****** TestMassage: $env:TestMessage ******" +# Image configuration +Write-Host "****** Image configuration ******" +Write-Host "Registry Server: $registryserver" +Write-Host "Repository: $repository" +Write-Host "Image Tag: $imagetag" +Write-Host "Container Image: $containerImage" + +# Azure Container Apps Related values +Write-Host "****** Azure Container Apps Related values ******" +Write-Host "Azure Container Apps Volumes Name: $aca_volumes_name" +Write-Host "Azure Container Apps Volume Mount Path: $aca_volume_mountPath" +Write-Host "Azure Container Apps Target Port: $aca_targetPort" + +# Azure Container Environment Related values +Write-Host "******Azure Container Environment Related values ******" +Write-Host "Azure Container Environment Fileshare Resource Group: $acenv_fileshare_resource_group" +Write-Host "Azure Container Environment Storage Account Name: $acenv_storage_account_name" +Write-Host "Azure Container Environment Fileshare Name: $acenv_fileshareName" +Write-Host "Azure Container Environment Volumes Storage Name: $acenv_volumes_storagename" + +# Common values +Write-Host "****** Common values *******" +Write-Host "Location: $location" +Write-Host "Container Registry Name: $containerRegistryName" +Write-Host "Container Registry Server: $registryserver" +Write-Host "Container Registry Username: $acrUsername" + +# deploy the template +az deployment group create ` + -g $resourceGroupName ` + --template-file $templateFile ` + --parameters name=$name ` + containerImage=$containerImage ` + targetPort=$aca_targetPort ` + aca_volume_mountPath=$aca_volume_mountPath ` + aca_volumes_name=$aca_volumes_name ` + maxReplicas=$aca_maxReplicas ` + minReplicas=$aca_minReplicas ` + acenv_fileshare_resource_group=$acenv_fileshare_resource_group ` + acenv_storage_account_name=$acenv_storage_account_name ` + acenv_fileshareName=$acenv_fileshareName ` + acenv_volumes_storagename=$acenv_volumes_storagename ` + location=$location ` + containerRegistryName=$containerRegistryName ` + registryserver=$registryserver ` + acrUsername=$acrUsername ` + acrPassword=$acrPassword ` + --query properties.outputs.fqdn.value \ No newline at end of file diff --git a/deploy_infra.ps1 b/deploy_infra.ps1 new file mode 100644 index 00000000..e0190836 --- /dev/null +++ b/deploy_infra.ps1 @@ -0,0 +1,112 @@ +param( + [string]$templateFile=".\infra\main.bicep", + # read pararmeters from .env file + $envParameters = $(Get-Content .\.env | ConvertFrom-StringData), + # get name from parameters + [string]$name=$env:name, + [string]$location=$envParameters.location, + # get createResourceGroup from parameters + [string]$createResourceGroup=$env:createResourceGroup, + + [string]$subscriptionId=$env:subscriptionId, + + # get resource group name from parameters + # if createResourceGroup is false, use the resource group name from parameters else + # use the name "name-rg" + [string]$resourceGroupName=$(if ($createResourceGroup -eq "false") { + $envParameters.resourceGroup} else { + "$name-rg"}), + [string]$containerRegistryName=$env:containerRegistryName, + + # Image configuration + # Get Container image from github workflow environment + [string]$registryserver=$env:registryserver, + [string]$containerImage=$env:containerImage, + + #Azure Container Environment Related values + [string]$acenv_fileshare_resource_group=$envParameters.acenv_fileshare_resource_group, + [string]$acenv_storage_account_name=$envParameters.acenv_storage_account_name, + [string]$acenv_fileshareName=$envParameters.acenv_fileshareName, + [string]$acenv_volumes_storagename=$envParameters.acenv_volumes_storagename, + + #Azure Container Apps Related values + [string]$aca_volumes_name=$envParameters.aca_volumes_name, + [string]$aca_volume_mountPath=$envParameters.aca_volume_mountPath , + [string]$aca_targetPort=$envParameters.targetPort, + [string]$aca_maxReplicas=$envParameters.maxReplicas, + [string]$aca_minReplicas=$envParameters.minReplicas + ) + +# set default subscription +az account set --subscription $subscriptionId + +#Write Container registry +write-host "Container Registry: $containerRegistryName" + +# Container registry username +[string]$acrUsername=$(az acr credential show -n $containerRegistryName --query username -o tsv) + + +# # Container registry password +# # TODO: use SecureString +# # TODO: use keyvault to store password +[string]$acrPassword=$(az acr credential show -n $containerRegistryName --query "passwords[0].value" -o tsv) + +# # Create a resource group with azure cli +# Create a resource group if $createResourceGroup is true +write-host "Create Resource Group: $createResourceGroup" + +if ($createResourceGroup -eq "true") { + Write-Host "Creating resource group $resourceGroupName" + az group create --name $resourceGroupName --location $location +} +Write-Host "Resource Group Name: $resourceGroupName" +# Test message +# Write-Host "****** TestMassage: $env:TestMessage ******" +# Image configuration +Write-Host "****** Image configuration ******" +Write-Host "Registry Server: $registryserver" +Write-Host "Container Image: $containerImage" + +# Azure Container Apps Related values +Write-Host "****** Azure Container Apps Related values ******" +Write-Host "Azure Container Apps Volumes Name: $aca_volumes_name" +Write-Host "Azure Container Apps Volume Mount Path: $aca_volume_mountPath" +Write-Host "Azure Container Apps Target Port: $aca_targetPort" + +# Azure Container Environment Related values +Write-Host "******Azure Container Environment Related values ******" +Write-Host "Azure Container Environment Fileshare Resource Group: $acenv_fileshare_resource_group" +Write-Host "Azure Container Environment Storage Account Name: $acenv_storage_account_name" +Write-Host "Azure Container Environment Fileshare Name: $acenv_fileshareName" +Write-Host "Azure Container Environment Volumes Storage Name: $acenv_volumes_storagename" + +# Common values +Write-Host "****** Common values *******" +Write-Host "Location: $location" +Write-Host "Container Registry Name: $containerRegistryName" +Write-Host "Container Registry Server: $registryserver" +Write-Host "Container Registry Username: $acrUsername" + +# deploy the template +Write-Host "Deploying the template" +az deployment group create ` + -g $resourceGroupName ` + --template-file $templateFile ` + --parameters name=$name ` + containerImage=$containerImage ` + targetPort=$aca_targetPort ` + aca_volume_mountPath=$aca_volume_mountPath ` + aca_volumes_name=$aca_volumes_name ` + maxReplicas=$aca_maxReplicas ` + minReplicas=$aca_minReplicas ` + acenv_fileshare_resource_group=$acenv_fileshare_resource_group ` + acenv_storage_account_name=$acenv_storage_account_name ` + acenv_fileshareName=$acenv_fileshareName ` + acenv_volumes_storagename=$acenv_volumes_storagename ` + location=$location ` + containerRegistryName=$containerRegistryName ` + registryserver=$registryserver ` + acrUsername=$acrUsername ` + acrPassword=$acrPassword ` + --query properties.outputs.fqdn.value \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 00000000..7a3114d5 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,23 @@ +version: '3.4' + +services: + + Petstore: + env_file: + - .env + image: ${registryserver}/${repository}:${imagetag} + build: + context: . + args: + - ENVIRONMENT=${ENVIRONMENT} + dockerfile: Dockerfile + no_cache: true + restart: always + ports: + - ${httpport}:8080 + - ${httpsport}:8443 + environment: + app.http.port: ${apphttpport} + app.https.port: ${apphttpsport} + app.name: ${appname} + app.version: ${appversion} \ No newline at end of file diff --git a/docker_build_img.ps1 b/docker_build_img.ps1 new file mode 100644 index 00000000..6d386cd6 --- /dev/null +++ b/docker_build_img.ps1 @@ -0,0 +1,10 @@ +# Run docker build with no cache +write-host "Building docker image with no cache" +write-host "$(Get-Location)" + +# # build +# docker build --no-cache --progress=plain . -t tdp:java17 2>&1 | Tee-Object -FilePath build.log + +# Compose up +write-host "Starting docker compose" +docker-compose up -d 2>&1 | Tee-Object -FilePath compose.log \ No newline at end of file diff --git a/infra/main.bicep b/infra/main.bicep new file mode 100644 index 00000000..db2a53dc --- /dev/null +++ b/infra/main.bicep @@ -0,0 +1,200 @@ +@description('Specifies the name of project.') +param name string + +@description('Specifies the name of the container app.') +param containerAppName string= '${name}-aca-app' + +@description('Specifies the name of the container app environment.') +param containerAppEnvName string = '${name}-aca-env' + +@description('Specifies the name of the log analytics workspace.') +param containerAppLogAnalyticsName string= '${name}-aca-loganalytics' + +@description('Specifies the location for all resources.') +param location string = resourceGroup().location + +// ACR Section +@description('Specifies the docker container image to deploy.') +param containerImage string + +@description('Specifies the name of the container registry.') +param registryserver string +@description('Specifies the name of the container registry.') +param containerRegistryName string + +@description('Specifies the username of the container registry.') +param acrUsername string + +@description('Specifies the password of the container registry.') +@secure() +param acrPassword string + +var aca_secret={ + acr_username: acrUsername + acr_password:acrPassword +} + +// ACA Section +@description('Specifies the container port.') +param targetPort int = 80 + +param aca_volume_mountPath string +param acenv_fileshareName string +param acenv_storage_account_name string +param acenv_volumes_storagename string +param aca_volumes_name string +param acenv_fileshare_resource_group string + +var aca_volumes={ + name: aca_volumes_name + storageName: acenv_volumes_storagename + storageType: 'AzureFile' + } +var aca_volumeMounts={ + mountPath: aca_volume_mountPath + volumeName: aca_volumes.name + } + +@description('Number of CPU cores the container can use. Can be with a maximum of two decimals.') +@allowed([ + '0.25' + '0.5' + '0.75' + '1' + '1.25' + '1.5' + '1.75' + '2' +]) +param cpuCore string = '0.5' + +@description('Amount of memory (in gibibytes, GiB) allocated to the container up to 4GiB. Can be with a maximum of two decimals. Ratio with CPU cores must be equal to 2.') +@allowed([ + '0.5' + '1' + '1.5' + '2' + '3' + '3.5' + '4' +]) +param memorySize string = '1' + +@description('Minimum number of replicas that will be deployed') +@minValue(0) +@maxValue(25) +param minReplicas int = 4 + +@description('Maximum number of replicas that will be deployed') +@minValue(0) +@maxValue(25) +param maxReplicas int = 7 + +resource containerAppLogAnalytics 'Microsoft.OperationalInsights/workspaces@2022-10-01' = { + name: containerAppLogAnalyticsName + location: location + properties: { + sku: { + name: 'PerGB2018' + } + } +} + resource azure_storage 'Microsoft.Storage/storageAccounts@2022-09-01' existing = { + name: acenv_storage_account_name + scope: resourceGroup(acenv_fileshare_resource_group) +} + +resource containerAppEnv 'Microsoft.App/managedEnvironments@2022-11-01-preview' = { + name: containerAppEnvName + location: location + properties: { + appLogsConfiguration: { + destination: 'log-analytics' + logAnalyticsConfiguration: { + customerId: containerAppLogAnalytics.properties.customerId + sharedKey: containerAppLogAnalytics.listKeys().primarySharedKey + } + } + + } + +} +resource storage 'Microsoft.App/managedEnvironments/storages@2022-11-01-preview' = { + name: aca_volumes.storageName + parent: containerAppEnv + properties: { + azureFile: { + accessMode: 'ReadWrite' + accountKey: azure_storage.listKeys().keys[0].value + accountName: azure_storage.name + shareName: acenv_fileshareName + } +} +} + +resource containerApp 'Microsoft.App/containerApps@2023-05-01'= { + name: containerAppName + location: location + properties: { + managedEnvironmentId: containerAppEnv.id + configuration: { + secrets: [ + { + name: containerRegistryName + value: aca_secret.acr_password + } + ] + ingress: { + external: true + targetPort: targetPort + allowInsecure: false + traffic: [ + { + latestRevision: true + weight: 100 + } + ] + } + registries: [ + { + passwordSecretRef: containerRegistryName + server: registryserver + username: acrUsername + } + ] + } + template: { + // revisionSuffix: 'rev' + containers: [ + { + name: containerAppName + image: containerImage + resources: { + cpu: json(cpuCore) + memory: '${memorySize}Gi' + } + volumeMounts: [ + { + mountPath: aca_volumeMounts.mountPath + volumeName: aca_volumes.name + } + ] + } + ] + scale: { + minReplicas: minReplicas + maxReplicas: maxReplicas + } + volumes: [ + { + name: aca_volumes.name + storageName: aca_volumes.storageName + storageType: aca_volumes.storageType + } + ] + + } + } +} + +output containerAppFQDN string = containerApp.properties.configuration.ingress.fqdn diff --git a/payload.md b/payload.md new file mode 100644 index 00000000..1a7f46ba --- /dev/null +++ b/payload.md @@ -0,0 +1,10 @@ +{ + "$content-type": "application/x-www-form-urlencoded", + "$content": "WE1MREFUQT0lM0MlM0Z4bWwrdmVyc2lvbiUzRCUyMjEuMCUyMitlbmNvZGluZyUzRCUyMklTTy04ODU5LTElMjIrc3RhbmRhbG9uZSUzRCUyMnllcyUyMiUzRiUzRSUwQSUzQ1Jlc3BvbnNlU2VydmljZStWZXJzaW9uJTNEJTIyMi4zJTIyJTNFJTBBKyslM0NIZWFkZXIlM0UlMEErKysrJTNDUGFydG5lciUzRU1JU1NjaWVuY2VzTVQlM0MlMkZQYXJ0bmVyJTNFJTBBKysrKyUzQ1Bhc3N3b3JkJTNFZ2VUcnUyNXMlM0MlMkZQYXNzd29yZCUzRSUwQSsrKyslM0NTZXJ2aWNlSUQlM0UxJTNDJTJGU2VydmljZUlEJTNFJTBBKyslM0MlMkZIZWFkZXIlM0UlMEErKyUzQ1Jlc3BvbnNlTGlzdCUzRSUwQSsrKyslM0NSZXNwb25zZStTZXF1ZW5jZU51bWJlciUzRCUyMjElMjIrVHlwZSUzRCUyMlNNUyUyMitGb3JtYXQlM0QlMjJUZXh0JTIyJTNFJTBBKysrKysrJTNDVHJhbnNhY3Rpb25JRCUzRTE3NTA2NjYyJTNDJTJGVHJhbnNhY3Rpb25JRCUzRSUwQSsrKysrKyUzQ09yaWdpbmF0aW5nTnVtYmVyJTNFMTIwMjQ5NDg5ODYlM0MlMkZPcmlnaW5hdGluZ051bWJlciUzRSUwQSsrKysrKyUzQ1RpbWUlM0UyMDI0MDIxNjIyNTYlM0MlMkZUaW1lJTNFJTBBKysrKysrJTNDRGF0YSUzRVRlc3QrLStURyUzQyUyRkRhdGElM0UlMEErKysrKyslM0NEZWxpdmVyZXIlM0UxMSUzQyUyRkRlbGl2ZXJlciUzRSUwQSsrKysrKyUzQ0Rlc3RpbmF0aW9uJTNFNjk2ODczJTNDJTJGRGVzdGluYXRpb24lM0UlMEErKysrKyslM0NPcGVyYXRvciUzRTMxMDAzJTNDJTJGT3BlcmF0b3IlM0UlMEErKysrJTNDJTJGUmVzcG9uc2UlM0UlMEErKyUzQyUyRlJlc3BvbnNlTGlzdCUzRSUwQSUzQyUyRlJlc3BvbnNlU2VydmljZSUzRSUwQQ==", + "$formdata": [ + { + "key": "XMLDATA", + "value": "\n\n
\n MISSciencesMT\n geTru25s\n 1\n
\n \n \n 17506662\n 12024948986\n \n Test - TG\n 11\n 696873\n 31003\n \n \n
\n" + } + ] +} diff --git a/payloadxml.md b/payloadxml.md new file mode 100644 index 00000000..5d447e60 --- /dev/null +++ b/payloadxml.md @@ -0,0 +1,4 @@ +{ + "name": "message", + "value": "\n\n
\n MISSciencesMT\n geTru25s\n 1\n
\n \n \n 17506662\n 12024948986\n \n Test - TG\n 11\n 696873\n 31003\n \n \n
\n" +} \ No newline at end of file diff --git a/pom.xml b/pom.xml index 51466520..3de7ac24 100644 --- a/pom.xml +++ b/pom.xml @@ -215,7 +215,7 @@ 1.0.0 2.0.27 2.1.10 - 2.12.1 + 2.15.2 2.0.5 9.4.9.v20180320 1.0.1 diff --git a/workflows/buildwithacr.yaml b/workflows/buildwithacr.yaml new file mode 100644 index 00000000..36ea1e4d --- /dev/null +++ b/workflows/buildwithacr.yaml @@ -0,0 +1,18 @@ +--- + name: "Build docker image using an azure container registry" + on: [push] + jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@master + - name: Login to Azure Container Registry + uses: azure/docker-login@v1 + with: + login-server: ${{ secrets.REGISTRY_NAME }}.azurecr.io + username: $(az acr credential show -n $azureacr --query username -o tsv)${{ secrets.REGISTRY_USERNAME }} + password: $(az acr credential show -n $containerRegistryName --query "passwords[0].value" -o tsv) + - name: Build docker image + run: docker build . -t ${{ secrets.REGISTRY_NAME }}.azurecr.io/${{ github.repository }}:latest + - name: Push docker image + run: docker push ${{ secrets.REGISTRY_NAME }}.azurecr.io/${{ github.repository }}:latest \ No newline at end of file diff --git a/workflows/deploytoaca.yml b/workflows/deploytoaca.yml new file mode 100644 index 00000000..aa24a6c8 --- /dev/null +++ b/workflows/deploytoaca.yml @@ -0,0 +1,74 @@ +name: Deploy to Azure +on: + push: + branches: + - master + pull_request: + types: [opened, synchronize, reopened, closed] + branches: + - master + +env: + TestMessage: "Hello from Environment" + RESOURCE_GROUP_NAME: ${{ secrets.RESOURCE_GROUP_NAME }} + AZURE_CREDENTIALS: ${{ secrets.AZURE_CREDENTIALS }} + TEMPLATE_FILE: "./infra/main.bicep" + SUBSCRIPTION_ID: ${{ secrets.SUBSCRIPTION_ID }} + CONTAINER_REGISTRY_NAME: ${{ secrets.CONTAINER_REGISTRY_NAME }} + +jobs: + build_and_deploy_job: + if: github.event_name == 'push' || (github.event_name == 'pull_request' && github.event.action != 'closed') + runs-on: ubuntu-latest + name: Build and Deploy Job + steps: + - name: Checkout + uses: actions/checkout@v3 + with: + submodules: true + - name: Log in to Azure + uses: azure/login@v1 + with: + creds: ${{ secrets.AZURE_CREDENTIALS }} + enable-AzPSSession: true # Set to 'true' to enable AzPSSession on the container. Default: false + + - name: Set default subscription + run: | + az account set --subscription $SUBSCRIPTION_ID + + - name: Get Container registry username + id: get-acr-username + run: | + echo "::set-output name=acr_username::$(az acr credential show -n $CONTAINER_REGISTRY_NAME --query username -o tsv)" + + - name: Get Container registry password + id: get-acr-password + run: | + echo "::set-output name=acr_password::$(az acr credential show -n $CONTAINER_REGISTRY_NAME --query "passwords[0].value" -o tsv)" + + - name: Create a resource group if not exist + run: | + az group create --name $RESOURCE_GROUP_NAME --location ${{ secrets.LOCATION }} + + - name: Deploy the template + run: | + az deployment group create \ + -g $RESOURCE_GROUP_NAME \ + --template-file $TEMPLATE_FILE \ + --parameters name=${{ secrets.NAME }} \ + containerImage=${{ secrets.CONTAINER_IMAGE }} \ + targetPort=${{ secrets.TARGET_PORT }} \ + aca_volume_mountPath=${{ secrets.ACA_VOLUME_MOUNT_PATH }} \ + aca_volumes_name=${{ secrets.ACA_VOLUMES_NAME }} \ + maxReplicas=${{ secrets.MAX_REPLICAS }} \ + minReplicas=${{ secrets.MIN_REPLICAS }} \ + acenv_fileshare_resource_group=${{ secrets.ACENV_FILESHARE_RESOURCE_GROUP }} \ + acenv_storage_account_name=${{ secrets.ACENV_STORAGE_ACCOUNT_NAME }} \ + acenv_fileshareName=${{ secrets.ACENV_FILESHARE_NAME }} \ + acenv_volumes_storagename=${{ secrets.ACENV_VOLUMES_STORAGENAME }} \ + location=${{ secrets.LOCATION }} \ + containerRegistryName=$CONTAINER_REGISTRY_NAME \ + registryserver=${{ secrets.REGISTRY_SERVER }} \ + acrUsername=${{ steps.get-acr-username.outputs.acr_username }} \ + acrPassword=${{ steps.get-acr-password.outputs.acr_password }} \ + --query properties.outputs.fqdn.value