Skip to content

Fix Dockerfile for Azure Container Registry builds #4

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

tmacam
Copy link

@tmacam tmacam commented Jun 22, 2023

Purpose

As commented in #3 by @horihiro:

According to the implementation of vscode-docker, it seems that the
Build image in Azure command uses the root of the workspace as a root
directory for container-building even if Dockerfile is in a
sub-directry.

This commit moves the Dockerfile to the root of the repository. This
file was updated to reflect this move, removed duplicate work from
COPY commands and ensure the same file work consistently for both
local builds and for Azure Container Registry builds.

Fixes #3

Also addresses MicrosoftDocs/azure-docs#101118

Does this introduce a breaking change?

[ ] Yes
[x] No

Pull Request Type

What kind of change does this Pull Request introduce?

[x] Bugfix
[ ] Feature
[ ] Code style update (formatting, local variables)
[ ] Refactoring (no functional changes, no api changes)
[ ] Documentation content changes
[ ] Other... Please describe:

How to Test

Get the code

git clone [repo-address]
cd [repo-name]
git checkout [branch-name]
npm install```

#### Test the code

For local build:

```bash
docker build --pull --rm -f "Dockerfile" -t containerappsalbumapijavascript:latest "." && \
docker run -p 3500:3500 containerappsalbumapijavascript:latest

For ACR builds, follow the steps as described on https://learn.microsoft.com/en-us/azure/container-apps/deploy-visual-studio-code#create-the-container-registry-and-docker-image up to the section and following sections up to (and including) "Create the container app and deploy the Docker image".

What to Check

For local builds, ensure docker run... executed previously runs successfully and outputs the following:

> node@1.0.0 start
> node ./bin/www

Container Apps Node Sample
Listening on port 3500

For ACR, ensure that the CApps creation was successful.

For both: also ensure the application is working by using curl:

$ curl http://localhost:3500/albums
[{"id":1,"title":"You, Me and an App ID","artist":"Daprize","price":56.99,"image_url":"https://aka.ms/albums-daprlogo"},{"id":2,"title":"Seven Revision Army","artist":"The Blue-Green Stripes","price":17.99,"image_url":"https://aka.ms/albums-containerappslogo"},{"id":3,"title":"Scale It Up","artist":"KEDA Club","price":39.99,"image_url":"https://aka.ms/albums-kedalogo"},{"id":4,"title":"Lost in Translation","artist":"MegaDNS","price":39.99,"image_url":"https://aka.ms/albums-envoylogo"},{"id":5,"title":"Lock Down your Love","artist":"V is for VNET","price":39.99,"image_url":"https://aka.ms/albums-vnetlogo"},{"id":6,"title":"Sweet Container O' Mine","artist":"Guns N Probeses","price":39.99,"image_url":"https://aka.ms/albums-containerappslogo"}

Replace localhost with the IP of the host exposed by ACA

Other Information

As commented in Azure-Samples#3 by @horihiro:

> According to the implementation of vscode-docker, it seems that the
> Build image in Azure command uses the root of the workspace as a root
> directory for container-building even if Dockerfile is in a
> sub-directry.

This commit moves the Dockerfile to the root of the repository. This
file was updated to reflect this move, removed duplicate work from
`COPY` commands and ensure the same file work consistently for both
local builds and for Azure Container Registry builds.

Fixes Azure-Samples#3

Also addresses MicrosoftDocs/azure-docs#101118

Signed-off-by: Tiago Alves Macambira <tmacam@burocrata.org>
@tmacam
Copy link
Author

tmacam commented Jun 22, 2023

Regarding updating the documentation, the only thing required is to remove the line --context-path ./src \ in the javascript section for https://github.com/MicrosoftDocs/azure-docs/blob/main/articles/container-apps/quickstart-code-to-cloud.md.

This file also states "The up command uses the Docker file in the root of the repository to build the container image." which is not the case for any of the samples at the moment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

file not found in build context or excluded by .dockerignore: stat package.json: file does not exist
1 participant