Browse Source
* Initial dev container changes * Update readme's * Clean up dev container * Cleanup * Use in-memory db * Indent * Update devcontainerreadme.md * Update appsettings.json * Update appsettings.json --------- Co-authored-by: bamurtaugh <brmurtau@microsoft.com>main
committed by
GitHub
6 changed files with 72 additions and 129 deletions
@ -1,82 +0,0 @@ |
|||
|
|||
#------------------------------------------------------------------------------------------------------------- |
|||
# Copyright (c) Microsoft Corporation. All rights reserved. |
|||
# Licensed under the MIT License. See https://go.microsoft.com/fwlink/?linkid=2090316 for license information. |
|||
#------------------------------------------------------------------------------------------------------------- |
|||
FROM mcr.microsoft.com/dotnet/sdk:7.0 |
|||
|
|||
|
|||
# This Dockerfile adds a non-root user with sudo access. Use the "remoteUser" |
|||
# property in devcontainer.json to use it. On Linux, the container user's GID/UIDs |
|||
# will be updated to match your local UID/GID (when using the dockerFile property). |
|||
# See https://aka.ms/vscode-remote/containers/non-root-user for details. |
|||
ARG USERNAME=vscode |
|||
ARG USER_UID=1000 |
|||
ARG USER_GID=$USER_UID |
|||
|
|||
# [Optional] Version of Node.js to install. |
|||
ARG INSTALL_NODE="false" |
|||
ARG NODE_VERSION="lts/*" |
|||
ENV NVM_DIR=/usr/local/share/nvm |
|||
|
|||
# [Optional] Install the Azure CLI |
|||
ARG INSTALL_AZURE_CLI="false" |
|||
|
|||
# Configure apt and install packages |
|||
RUN apt-get update \ |
|||
&& export DEBIAN_FRONTEND=noninteractive \ |
|||
&& apt-get -y install --no-install-recommends apt-utils dialog 2>&1 \ |
|||
# |
|||
# Verify git, process tools, lsb-release (common in install instructions for CLIs) installed |
|||
&& apt-get -y install git openssh-client less iproute2 procps apt-transport-https gnupg2 curl lsb-release \ |
|||
# |
|||
# Create a non-root user to use if preferred - see https://aka.ms/vscode-remote/containers/non-root-user. |
|||
&& groupadd --gid $USER_GID $USERNAME \ |
|||
&& useradd -s /bin/bash --uid $USER_UID --gid $USER_GID -m $USERNAME \ |
|||
# [Optional] Add sudo support for the non-root user |
|||
&& apt-get install -y sudo \ |
|||
&& echo $USERNAME ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/$USERNAME\ |
|||
&& chmod 0440 /etc/sudoers.d/$USERNAME \ |
|||
# |
|||
# [Optional] Install Node.js for ASP.NET Core Web Applicationss |
|||
&& if [ "$INSTALL_NODE" = "true" ]; then \ |
|||
# |
|||
# Install nvm and Node |
|||
mkdir -p ${NVM_DIR} \ |
|||
&& curl -so- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.3/install.sh | bash 2>&1 \ |
|||
&& chown -R ${USER_UID}:${USER_GID} ${NVM_DIR} \ |
|||
&& /bin/bash -c "source $NVM_DIR/nvm.sh \ |
|||
&& nvm alias default ${NODE_VERSION}" 2>&1 \ |
|||
&& echo '[ -s "$NVM_DIR/nvm.sh" ] && \\. "$NVM_DIR/nvm.sh" && [ -s "$NVM_DIR/bash_completion" ] && \\. "$NVM_DIR/bash_completion"' \ |
|||
| tee -a /home/${USERNAME}/.bashrc /home/${USERNAME}/.zshrc >> /root/.zshrc \ |
|||
&& echo "if [ \"\$(stat -c '%U' ${NVM_DIR})\" != \"${USERNAME}\" ]; then sudo chown -R ${USER_UID}:root ${NVM_DIR}; fi" \ |
|||
| tee -a /root/.bashrc /root/.zshrc /home/${USERNAME}/.bashrc >> /home/${USERNAME}/.zshrc \ |
|||
&& chown ${USER_UID}:${USER_GID} /home/${USERNAME}/.bashrc /home/${USERNAME}/.zshrc \ |
|||
&& chown -R ${USER_UID}:root ${NVM_DIR} \ |
|||
# |
|||
# Install yarn |
|||
&& curl -sS https://dl.yarnpkg.com/$(lsb_release -is | tr '[:upper:]' '[:lower:]')/pubkey.gpg | apt-key add - 2>/dev/null \ |
|||
&& echo "deb https://dl.yarnpkg.com/$(lsb_release -is | tr '[:upper:]' '[:lower:]')/ stable main" | tee /etc/apt/sources.list.d/yarn.list \ |
|||
&& apt-get update \ |
|||
&& apt-get -y install --no-install-recommends yarn; \ |
|||
fi \ |
|||
# |
|||
# [Optional] Install the Azure CLI |
|||
&& if [ "$INSTALL_AZURE_CLI" = "true" ]; then \ |
|||
echo "deb [arch=amd64] https://packages.microsoft.com/repos/azure-cli/ $(lsb_release -cs) main" > /etc/apt/sources.list.d/azure-cli.list \ |
|||
&& curl -sL https://packages.microsoft.com/keys/microsoft.asc | apt-key add - 2>/dev/null \ |
|||
&& apt-get update \ |
|||
&& apt-get install -y azure-cli; \ |
|||
fi \ |
|||
# |
|||
# Install EF Core dotnet tool |
|||
&& dotnet tool install dotnet-ef --tool-path /home/$USERNAME/.dotnet/tools \ |
|||
&& chown -R $USERNAME /home/$USERNAME/.dotnet \ |
|||
# |
|||
# Clean up |
|||
&& apt-get autoremove -y \ |
|||
&& apt-get clean -y \ |
|||
&& rm -rf /var/lib/apt/lists/* |
|||
|
|||
# Set PATH for dotnet tools |
|||
ENV PATH "$PATH:/home/$USERNAME/.dotnet/tools" |
|||
@ -0,0 +1,36 @@ |
|||
# Dev container |
|||
|
|||
This project includes a [dev container](https://containers.dev/), which lets you use a container as a full-featured dev environment. |
|||
|
|||
You can use the dev container configuration in this folder to build and run the app without needing to install any of its tools locally! You can use it in [GitHub Codespaces](https://github.com/features/codespaces) or the [VS Code Dev Containers extension](https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-containers). |
|||
|
|||
## GitHub Codespaces |
|||
Follow these steps to open this sample in a Codespace: |
|||
1. Click the **Code** drop-down menu at the top of https://github.com/dotnet-architecture/eShopOnWeb. |
|||
1. Click on the **Codespaces** tab. |
|||
1. Click **Create codespace on main** . |
|||
|
|||
For more info, check out the [GitHub documentation](https://docs.github.com/en/free-pro-team@latest/github/developing-online-with-codespaces/creating-a-codespace#creating-a-codespace). |
|||
|
|||
## VS Code Dev Containers |
|||
|
|||
If you already have VS Code and Docker installed, you can click [here](https://vscode.dev/redirect?url=vscode://ms-vscode-remote.remote-containers/cloneInVolume?url=https://github.com/dotnet-architecture/eShopOnWeb) to get started. This will cause VS Code to automatically install the Dev Containers extension if needed, clone the source code into a container volume, and spin up a dev container for use. |
|||
|
|||
You can also follow these steps to open this sample in a container using the VS Code Dev Containers extension: |
|||
|
|||
1. If this is your first time using a development container, please ensure your system meets the pre-reqs (i.e. have Docker installed) in the [getting started steps](https://aka.ms/vscode-remote/containers/getting-started). |
|||
|
|||
2. Open a locally cloned copy of the code: |
|||
|
|||
- Clone this repository to your local filesystem. |
|||
- Press <kbd>F1</kbd> and select the **Dev Containers: Open Folder in Container...** command. |
|||
- Select the cloned copy of this folder, wait for the container to start, and try things out! |
|||
|
|||
You can learn more in the [Dev Containers documentation](https://code.visualstudio.com/docs/devcontainers/containers). |
|||
|
|||
## Tips and tricks |
|||
|
|||
* Since the dev container is Linux-based, you won't be able to use LocalDB. Add ` "UseOnlyInMemoryDatabase": true,` to the [appsettings.json](../src/Web/appsettings.json) file (there's additional context on this [in the app's readme](../README.md#configuring-the-sample-to-use-sql-server)). |
|||
* If you get a `502 bad gateway` error, you may need to set your port to the https protocol. You can do this by opening the Ports view in VS Code (**Ports: Focus on Ports View**), right-clicking on the port you're using, select **Change Port Protocol**, and set **https**. |
|||
* If you are working with the same repository folder in a container and Windows, you'll want consistent line endings (otherwise you may see hundreds of changes in the SCM view). The `.gitattributes` file in the root of this repo disables line ending conversion and should prevent this. See [tips and tricks](https://code.visualstudio.com/docs/devcontainers/tips-and-tricks#_resolving-git-line-ending-issues-in-containers-resulting-in-many-modified-files) for more info. |
|||
* If you'd like to review the contents of the image used in this dev container, you can check it out in the [devcontainers/images](https://github.com/devcontainers/images/tree/main/src/dotnet) repo. |
|||
@ -0,0 +1,3 @@ |
|||
* text=auto eol=lf |
|||
*.{cmd,[cC][mM][dD]} text eol=crlf |
|||
*.{bat,[bB][aA][tT]} text eol=crlf |
|||
Loading…
Reference in new issue