Skip to content

Commit

Permalink
Minor enhancements to simplified init (#2756)
Browse files Browse the repository at this point in the history
Make a few minor enhancements to simplified init workflow:

1. Add heuristic detection for various async python and javascript libraries
2. Fix lint error for unused `apiUrls` for frontend only app
3. Rename directory `lib` -> `modules` to avoid being accidentally excluded by python .gitignore
4. Update next-steps readme

Fixes #2654
  • Loading branch information
weikanglim committed Sep 18, 2023
1 parent d6a5880 commit d2acc39
Show file tree
Hide file tree
Showing 8 changed files with 73 additions and 18 deletions.
7 changes: 6 additions & 1 deletion cli/azd/.vscode/cspell-azd-dictionary.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# hyphen is optional, "re-authentication" and "reauthentication" are equivalent.
AADSTS
ABRT
aiomysql
aiopg
alphafeatures
apimanagement
apims
Expand All @@ -17,6 +18,8 @@ armapimanagement
armappconfiguration
armappplatform
armcognitiveservices
asyncmy
asyncpg
azapi
AZCLI
azcorelog
Expand Down Expand Up @@ -101,6 +104,7 @@ microsoftonline
missingkey
mockarmresources
mockazcli
mongojs
mvnw
mysqldb
mysqlclient
Expand All @@ -124,6 +128,7 @@ pflag
preinit
proxying
psycopg
psycopgbinary
pulumi
pyapp
pyproject
Expand Down
4 changes: 2 additions & 2 deletions cli/azd/internal/appdetect/javascript.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,9 @@ func (nd *javaScriptDetector) DetectProject(path string, entries []fs.DirEntry)
switch dep {
case "mysql":
databaseDepMap[DbMySql] = struct{}{}
case "mongodb":
case "mongodb", "mongojs", "mongoose":
databaseDepMap[DbMongo] = struct{}{}
case "pg-promise":
case "pg", "pg-promise":
databaseDepMap[DbPostgres] = struct{}{}
case "tedious":
databaseDepMap[DbSqlServer] = struct{}{}
Expand Down
16 changes: 13 additions & 3 deletions cli/azd/internal/appdetect/python.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,21 @@ func (pd *pythonDetector) DetectProject(path string, entries []fs.DirEntry) (*Pr
}

switch module {
case "flask_mysqldb", "mysqlclient":
case "flask_mysqldb",
"mysqlclient",
"aiomysql",
"asyncmy":
databaseDepMap[DbMySql] = struct{}{}
case "psycopg2", "psycopg2-binary":
case "psycopg2",
"psycopg2-binary",
"psycopg",
"psycopgbinary",
"asyncpg",
"aiopg":
databaseDepMap[DbPostgres] = struct{}{}
case "pymongo", "beanie":
case "pymongo",
"beanie",
"motor":
databaseDepMap[DbMongo] = struct{}{}
}
}
Expand Down
12 changes: 12 additions & 0 deletions cli/azd/internal/scaffold/scaffold_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,18 @@ func TestExecInfra(t *testing.T) {
},
},
},
{
"Web only",
InfraSpec{
Services: []ServiceSpec{
{
Name: "web",
Port: 3100,
Frontend: &Frontend{},
},
},
},
},
{
"API and web",
InfraSpec{
Expand Down
4 changes: 2 additions & 2 deletions cli/azd/resources/scaffold/templates/host-containerapp.bicept
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ param databaseName string
@secure()
param databasePassword string
{{- end}}
{{- if .Frontend}}
{{- if (and .Frontend .Frontend.Backends)}}
param apiUrls array
{{- end}}
{{- if (and .Backend .Backend.Frontends)}}
Expand Down Expand Up @@ -54,7 +54,7 @@ resource acrPullRole 'Microsoft.Authorization/roleAssignments@2022-04-01' = {
}
}

module fetchLatestImage '../lib/fetch-container-image.bicep' = {
module fetchLatestImage '../modules/fetch-container-image.bicep' = {
name: '${name}-fetch-image'
params: {
exists: exists
Expand Down
2 changes: 1 addition & 1 deletion cli/azd/resources/scaffold/templates/main.bicept
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ module {{bicepName .Name}} './app/{{.Name}}.bicep' = {
databaseUser: postgresDb.outputs.databaseUser
databasePassword: vault.getSecret(postgresDb.outputs.databaseConnectionKey)
{{- end}}
{{- if .Frontend}}
{{- if (and .Frontend .Frontend.Backends)}}
apiUrls: [
{{- range .Frontend.Backends}}
{{bicepName .Name}}.outputs.uri
Expand Down
46 changes: 37 additions & 9 deletions cli/azd/resources/scaffold/templates/next-steps.mdt
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,30 @@

### Define environment variables for running services

Modify or add environment variables to configure the running application. Environment variables can be configured by modifying the `env` node in the following files:
{{range .Services}}
- [app/{{.Name}}.bicep](./infra/app/{{.Name}}.bicep)
1. Modify or add environment variables to configure the running application. Environment variables can be configured by modifying the `env` node in the following files:
{{- range .Services}}
- [app/{{.Name}}.bicep](./infra/app/{{.Name}}.bicep)
{{- end}}

To define a secret as an environment variable under `env`, the variable should be added with a `secretRef` pointing to a `secrets` entry or a stored KeyVault secret.
2. For services using a database, environment variables have been pre-configured under `env` to allow connection to the database. Modify the name of these variables as needed to match your application.
3. To set a secret or API key as an environment variable under `env`, the variable should be added with a `secretRef` pointing to a `secrets` entry or a stored KeyVault secret.

### Provision infrastructure and deploy application code

Run `azd up` to provision your infrastructure and deploy to Azure in one step (or run `azd provision` then `azd deploy` to accomplish the tasks separately). Visit the service endpoints listed to see your application up-and-running!

To troubleshoot any issues, see [troubleshooting](#troubleshooting).

### Configure CI/CD pipeline

1. Create a workflow pipeline file locally. The following starters are available:
- [Deploy with GitHub Actions](https://github.com/Azure-Samples/azd-starter-bicep/blob/main/.github/workflows/azure-dev.yml)
- [Deploy with Azure Pipelines](https://github.com/Azure-Samples/azd-starter-bicep/blob/main/.azdo/pipelines/azure-dev.yml)
2. Run `azd pipeline config -e <environment name>` to configure the deployment pipeline to connect securely to Azure. An environment name is specified here to configure the pipeline with a different environment for isolation purposes. Run `azd env list` and `azd env set` to reselect the default environment after this step.

## What was added

### Infrastructure configuration

To describe the infrastructure and application, `azure.yaml` along with Infrastructure as Code files using Bicep were added with the following directory structure:

```yaml
Expand Down Expand Up @@ -54,7 +63,26 @@ Each bicep file declares resources to be provisioned. The resources are provisio

More information about [Bicep](https://aka.ms/bicep) language.

If your project does not contain a Dockerfile, we will use [Buildpacks](https://buildpacks.io/) to create an image for the services in `azure.yaml` and get your containerized app onto Azure.
### Build from source (no Dockerfile)

*Note: Build from source is currently experimental. We recommend authoring a Dockerfile for a static front-end service.*

#### Build with Buildpacks using Oryx

If your project does not contain a Dockerfile, we will use [Buildpacks](https://buildpacks.io/) using [Oryx](https://github.com/microsoft/Oryx/blob/main/doc/README.md) to create an image for the services in `azure.yaml` and get your containerized app onto Azure.

To produce and run the docker image locally:

1. Run `azd package` to build the image.
2. Copy the *Image Tag* shown.
3. Run `docker run -it <Image Tag>` to run the image locally.

#### Exposed port

Oryx will automatically set `PORT` to a default value of `80` or `8080` depending on the language. Additionally, it will auto-configure supported web servers such as `gunicorn` and `ASP .NET Core` to listen to the target `PORT`. If your application already listens to the port specified by the `PORT` variable, the application will work out-of-the-box. Otherwise, you may need to perform one of the steps below:

1. Update your application code or configuration to listen to the port specified by the `PORT` variable
1. (Alternatively) Search for `targetPort` in a .bicep file under the `infra/app` folder, and update the variable to match the port used by the application.

## Billing

Expand All @@ -70,10 +98,10 @@ A: Your service may have failed to start or misconfigured. To investigate furthe
2. Navigate to the specific Azure Container App resource for the service.
3. Select *Monitoring -> Log stream* under the navigation pane.
4. Observe the log output to identify any errors.
5. If there are no errors, ensure that the ingress port matches the port that your service listens on:
5. If there are no errors, ensure that the ingress target port matches the port that your service listens on:
1. Under *Settings -> Ingress*, ensure the *Target port* matches the desired port.
2. After modifying this setting, ensure the setting is also updated in the local bicep configuration file.
6. If logs are written to disk, examine the local logs by using the *Console* to connect to a shell within the running container.
2. After modifying this setting, also update the `targetPort` setting in the .bicep file for the service under `infra/app`.
6. If logs are written to disk, examine the local logs or debug the application by using the *Console* to connect to a shell within the running container.

For additional information about setting up your `azd` project, visit our official [docs](https://learn.microsoft.com/en-us/azure/developer/azure-developer-cli/make-azd-compatible?pivots=azd-convert).
{{ end}}

0 comments on commit d2acc39

Please sign in to comment.