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

Buildtoacr 01082024 #114

Open
wants to merge 50 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
dc48afa
initial deployment
hartou Jul 30, 2023
a65e510
remove env
hartou Jul 30, 2023
68fb603
Update .env
hartou Jul 30, 2023
074d9fc
remove .env
hartou Jul 30, 2023
83614bb
ignore vscode
hartou Jul 30, 2023
936e6dc
remove .env
hartou Jul 30, 2023
858f5c9
update gitignore
hartou Jul 30, 2023
efd7aff
remove compose.log
hartou Jul 30, 2023
0120ec4
delete compose.log
hartou Jul 30, 2023
e10b184
Update todo.md
hartou Jul 30, 2023
3b622b1
github action
hartou Jul 30, 2023
b5872cb
remove todo.md
hartou Jan 8, 2024
36d7118
Initial build to acr
hartou Jan 9, 2024
c9a5735
github actions init
hartou Jan 17, 2024
d2cc9e8
List Directory
hartou Jan 26, 2024
06d5e29
ignore creds.json
hartou Jan 29, 2024
137783b
Improve github actions
hartou Feb 13, 2024
33f6884
dockerfile
hartou Feb 13, 2024
bc1b1cd
add login to azure permission
hartou Feb 13, 2024
a548bd3
login with azure
hartou Feb 13, 2024
5bb6d81
azure login
hartou Feb 13, 2024
cfb398c
Testing Azure Login
hartou Feb 13, 2024
2f2f17d
ACA deployment
hartou Feb 13, 2024
835472d
deploy aca
hartou Feb 13, 2024
03b950b
aca deploy
hartou Feb 13, 2024
193052d
aca deploy
hartou Feb 13, 2024
a029ff8
ACA deploy 1
hartou Feb 13, 2024
61cc4bc
deploy tdpmqv7
hartou Feb 13, 2024
e851261
Add environment variable and test message
hartou Feb 14, 2024
5eab450
Update function to handle edge cases
hartou Feb 14, 2024
fcc230b
Add environment variable output in deployment script
hartou Feb 14, 2024
bd04a18
Update TestMessage variable in workflow.yaml
hartou Feb 14, 2024
8664da4
Update deployment script and workflow
hartou Feb 14, 2024
2e61bef
Update environment variables and workflow configuration
hartou Feb 14, 2024
3576d90
Update Docker build command and Azure Container App resource version
hartou Feb 14, 2024
c354d69
Update containerImage in workflow.yaml
hartou Feb 14, 2024
ea809ad
Add Azure login step to workflow.yaml
hartou Feb 14, 2024
e9ef7d9
Update Docker build command in workflow.yaml
hartou Feb 14, 2024
1f5d769
Refactor Docker image build command in workflow.yaml
hartou Feb 14, 2024
6a72a1c
Fix indentation in Docker build command
hartou Feb 14, 2024
a3d696b
Refactor Docker build command
hartou Feb 14, 2024
c6913a2
Update workflow.yaml to deploy Azure Container App
hartou Feb 14, 2024
ca8d5e0
Update environment variables and container image configuration
hartou Feb 14, 2024
9279d32
Update environment variables and workflow configuration
hartou Feb 16, 2024
303753c
Update workflow.yaml and deploy_infra.ps1
hartou Feb 21, 2024
9498b56
Update workflow.yaml file
hartou Feb 21, 2024
d31c493
Update environment variable name in workflow.yaml
hartou Feb 21, 2024
3f27059
Update workflow.yaml: change createResourceGroup and name values
hartou Feb 21, 2024
5e1bf9b
Add deployment message
hartou Feb 21, 2024
9c41c80
Update containerImage in workflow.yaml
hartou Feb 27, 2024
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: 2 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# ignore the target directory
target/
29 changes: 29 additions & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -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
43 changes: 43 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -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
69 changes: 69 additions & 0 deletions .github/workflows/workflow.yaml
Original file line number Diff line number Diff line change
@@ -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 }}

10 changes: 10 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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
```
4 changes: 4 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"java.configuration.updateBuildConfiguration": "interactive",
"java.compile.nullAnalysis.mode": "automatic"
}
25 changes: 20 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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

Expand Down
118 changes: 118 additions & 0 deletions archive/deploy_infra_archive_02142023.ps1
Original file line number Diff line number Diff line change
@@ -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 <container registry>/<image name>:<image tag>
# [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
Loading