Skip to content

Commit

Permalink
Merge branch 'snehpar/test-oidc' into snehapar/test-private-registry
Browse files Browse the repository at this point in the history
  • Loading branch information
snehapar9 committed Nov 11, 2023
2 parents a1fd970 + 4bae842 commit e214177
Show file tree
Hide file tree
Showing 6 changed files with 224 additions and 99 deletions.
13 changes: 13 additions & 0 deletions .github/workflows/run-validation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ env:
jobs:
create-using-builder:


name: 'Create app using builder'
runs-on: ubuntu-latest
timeout-minutes: 10
Expand Down Expand Up @@ -60,6 +61,12 @@ jobs:
shell: bash
run: az containerapp delete -n ${{ env.TEST_CONTAINER_APP_NAME }} -g ${{ vars.TEST_RESOURCE_GROUP_NAME }} -y

- name: Delete pushed image
if: ${{ always() }}
shell: bash
run: az acr repository delete -n ${{ vars.TEST_ACR_NAME }} -t ${{ env.TEST_IMAGE_REPOSITORY }}:${{ env.TEST_IMAGE_TAG }} -y


create-using-builder-and-internal-registry:

name: 'Create app using builder and push to internal registry'
Expand Down Expand Up @@ -141,6 +148,11 @@ jobs:
shell: bash
run: az containerapp delete -n ${{ env.TEST_CONTAINER_APP_NAME }} -g ${{ vars.TEST_RESOURCE_GROUP_NAME }} -y

- name: Delete pushed image
if: ${{ always() }}
shell: bash
run: az acr repository delete -n ${{ vars.TEST_ACR_NAME }} -t ${{ env.TEST_IMAGE_REPOSITORY }}:${{ env.TEST_IMAGE_TAG }} -y

create-using-provided-dockerfile:

name: 'Create app using provided Dockerfile'
Expand Down Expand Up @@ -190,6 +202,7 @@ jobs:
shell: bash
run: az acr repository delete -n ${{ vars.TEST_ACR_NAME }} -t ${{ env.TEST_IMAGE_REPOSITORY }}:${{ env.TEST_IMAGE_TAG }} -y


create-using-image-linux:

name: 'Create app using image on Linux runner'
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ For more information on the structure of the YAML configuration file, please vis
| `resourceGroup` | No | The existing resource group that the Azure Container App will be created in. If not provided, this value will be `<container-app-name>-rg` and its existence will first be checked before attempting to create it. |
| `containerAppEnvironment` | No | The name of the Container App environment to use with the application. If not provided, an existing environment in the resource group of the Container App will be used, otherwise, an environment will be created in the formation `<container-app-name>-env`. |
| `runtimeStack` | No | The platform version stack used in the final runnable application image that is deployed to the Container App. The value should be provided in the formation `<platform>:<version>`. If not provided, this value is determined by Oryx based on the contents of the provided application. Please refer to [this document](https://github.com/microsoft/Oryx/blob/main/doc/supportedRuntimeVersions.md) for more information on supported runtime stacks for Oryx. |
| `builderStack` | No | The stack (OS) that should be used to build the provided application source and produce the runnable application image. You can provide a specific image tag for the stack, such as "debian-bookworm-20231004.1", or you can provide a supported stack name, such as "debian-bookworm" or "debian-bullseye", and the latest supported image tag for that stack will be used. If no stack is provided, this action will attempt to build the provided application source with each supported stack until there's a successful build. |
| `builderStack` | No | The stack (OS) that should be used to build the provided application source and produce the runnable application image. You can provide a specific image tag for the stack, such as "debian-bookworm-20231107.2", or you can provide a supported stack name, such as "debian-bookworm" or "debian-bullseye", and the latest supported image tag for that stack will be used. If no stack is provided, this action will attempt to build the provided application source with each supported stack until there's a successful build. |
| `targetPort` | No | The designated port for the application to run on. If no value is provided and the builder is used to build the runnable application image, the target port will be set to 80 for Python applications and 8080 for all other platform applications. If no value is provided when creating a Container App, the target port will default to 80. Note: when using this action to update a Container App, the target port may be updated if not provided based on changes to the ingress property. |
| `location` | No | The location that the Container App (and other created resources) will be deployed to. To view locations suitable for creating the Container App in, please run the following: `az provider show -n Microsoft.App --query "resourceTypes[?resourceType=='containerApps'].locations"` |
| `environmentVariables` | No | A list of environment variable(s) for the container. Space-separated values in 'key=value' format. Empty string to clear existing values. Prefix value with 'secretref:' to reference a secret. |
Expand Down
2 changes: 1 addition & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ inputs:
builderStack:
description: |
'The stack (OS) that should be used to build the provided application source and produce the runnable application
image. You can provide a specific image tag for the stack, such as "debian-bullseye-20231004.1", or you can
image. You can provide a specific image tag for the stack, such as "debian-bullseye-20231107.2", or you can
provide a supported stack name, such as "debian-bookworm" or "debian-bullseye", and the latest supported image tag
for that stack will be used. If no stack is provided, this action will attempt to build the provided application
source with each supported stack until there's a successful build.'
Expand Down
51 changes: 33 additions & 18 deletions azurecontainerapps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,18 @@ export class azurecontainerapps {
await this.authenticateAzureContainerRegistryAsync();
}

// Set up property to determine if the internal registry should be used
this.useInternalRegistry = this.util.isNullOrEmpty(this.registryUrl);
// Set up property to determine if the internal registry should be used
this.useInternalRegistry = this.util.isNullOrEmpty(this.registryUrl);

// Set up property to trigger cloud build with 'up' command
this.shouldCreateOrUpdateContainerAppWithUp = !this.util.isNullOrEmpty(this.appSourcePath) && this.useInternalRegistry;
// Set up property to trigger cloud build with 'up' command
this.shouldCreateOrUpdateContainerAppWithUp = !this.util.isNullOrEmpty(this.appSourcePath) && this.useInternalRegistry;

// If the application source was provided, build a runnable application image from it
if (!this.useInternalRegistry && !this.util.isNullOrEmpty(this.appSourcePath)) {
if (!this.useInternalRegistry && !this.util.isNullOrEmpty(this.appSourcePath)) {
await this.buildAndPushImageAsync();
}
Expand Down Expand Up @@ -180,8 +185,8 @@ export class azurecontainerapps {
* setting the Azure CLI to install missing extensions.
*/
private static async setupAzureCli() {
// Set the Azure CLI to install missing extension
await this.util.installAzureCliExtension();
// Set the Azure CLI to install missing extensions
// await this.util.installAzureCliExtension();
}

/**
Expand Down Expand Up @@ -233,6 +238,12 @@ export class azurecontainerapps {
// Set deployment location, if provided
let location: string = this.toolHelper.getInput('location', false);

let doesContainerAppExist = await this.appHelper.doesContainerAppExist(this.containerAppName, this.resourceGroup);
if (doesContainerAppExist) {
var environmentId = await this.appHelper.getExistingContainerAppEnvironmentId(this.containerAppName);
var environmentName = environmentId.split("/").pop();
location = await this.appHelper.getExistingContainerAppEnvironmentLocation(environmentName);
}
// If no location was provided, use the default location for the Container App service
if (this.util.isNullOrEmpty(location)) {
location = await this.appHelper.getDefaultContainerAppLocation();
Expand Down Expand Up @@ -304,6 +315,9 @@ export class azurecontainerapps {
await this.appHelper.createContainerAppEnvironment(containerAppEnvironment, resourceGroup, location);
}

// Set default location to the location of the Container App environment
this.location = await this.appHelper.getExistingContainerAppEnvironmentLocation(containerAppEnvironment);

return containerAppEnvironment;
}

Expand Down Expand Up @@ -346,25 +360,26 @@ export class azurecontainerapps {
// If telemetry is enabled, log that the previously built image scenario was targeted for this task
this.telemetryHelper.setImageScenario();
}

/**
* Builds a runnable application image using a Dockerfile or the builder and pushes it to the Container Registry.
*/
private static async buildAndPushImageAsync() {
// Get the name of the image to build if it was provided, or generate it from build variables
this.imageToBuild = this.toolHelper.getInput('imageToBuild', false);

if (this.util.isNullOrEmpty(this.imageToBuild)) {
const imageRepository = this.toolHelper.getDefaultImageRepository()
// Constructs the image to build based on the provided registry URL, image repository, build ID, and build number.
this.imageToBuild = `${this.registryUrl}/${imageRepository}:${this.buildId}.${this.buildNumber}`;
this.toolHelper.writeInfo(`Default image to build: ${this.imageToBuild}`);
}

// Get the name of the image to deploy if it was provided, or set it to the value of 'imageToBuild'
if (this.util.isNullOrEmpty(this.imageToDeploy)) {
this.imageToDeploy = this.imageToBuild;
this.toolHelper.writeInfo(`Default image to deploy: ${this.imageToDeploy}`);
}
// Get the name of the image to build if it was provided, or generate it from build variables
this.imageToBuild = this.toolHelper.getInput('imageToBuild', false);

if (this.util.isNullOrEmpty(this.imageToBuild)) {
const imageRepository = this.toolHelper.getDefaultImageRepository()
// Constructs the image to build based on the provided registry URL, image repository, build ID, and build number.
this.imageToBuild = `${this.registryUrl}/${imageRepository}:${this.buildId}.${this.buildNumber}`;
this.toolHelper.writeInfo(`Default image to build: ${this.imageToBuild}`);
}

// Get the name of the image to deploy if it was provided, or set it to the value of 'imageToBuild'
if (this.util.isNullOrEmpty(this.imageToDeploy)) {
this.imageToDeploy = this.imageToBuild;
this.toolHelper.writeInfo(`Default image to deploy: ${this.imageToDeploy}`);
}

// Get Dockerfile to build, if provided, or check if one exists at the root of the provided application
let dockerfilePath: string = this.toolHelper.getInput('dockerfilePath', false);
Expand Down Expand Up @@ -546,7 +561,7 @@ export class azurecontainerapps {
// Create the Container App from the YAML configuration file
await this.appHelper.createContainerAppFromYaml(this.containerAppName, this.resourceGroup, this.yamlConfigPath);
} else if (this.shouldCreateOrUpdateContainerAppWithUp) {
await this.appHelper.createOrUpdateContainerAppWithUp(this.containerAppName, this.resourceGroup, this.commandLineArgs);
await this.appHelper.createOrUpdateContainerAppWithUp(this.containerAppName, this.resourceGroup, this.commandLineArgs, this.location);
} else {
// Create the Container App from command line arguments
await this.appHelper.createContainerApp(this.containerAppName, this.resourceGroup, this.containerAppEnvironment, this.commandLineArgs);
Expand Down
Loading

0 comments on commit e214177

Please sign in to comment.