-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enable local development for *nix environments using docker
- Loading branch information
1 parent
f8ccae8
commit cadb613
Showing
9 changed files
with
172 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
ARG BASE_IMAGE_SUFFIX | ||
|
||
FROM mcr.microsoft.com/dotnet/core/sdk:3.1-buster${BASE_IMAGE_SUFFIX} AS builder | ||
ENV DOTNET_CLI_TELEMETRY_OPTOUT=1 | ||
ENV NO_DOCKER 1 | ||
ENV IN_DOCKER 1 | ||
|
||
RUN apt update && apt install -y \ | ||
build-essential \ | ||
&& rm -rf /var/lib/apt/lists/* | ||
# For compile Less style files in pre-build stage | ||
RUN apt-get update \ | ||
&& curl -sL https://deb.nodesource.com/setup_14.x | bash \ | ||
&& apt-get install -y nodejs | ||
|
||
WORKDIR /src | ||
COPY ./ /src/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# Supported environment: Unix-like / Powershell | ||
SELF_DIR := $(dir $(lastword $(MAKEFILE_LIST))) | ||
|
||
DOCKER_COMPOSE_CMD := docker-compose -f $(SELF_DIR)docker-compose.dev.yml | ||
|
||
ifeq (,${NO_DOCKER}) | ||
DOCKER_RUN := $(DOCKER_COMPOSE_CMD) run --rm web | ||
else | ||
DOCKER_RUN := | ||
endif | ||
|
||
.PHONY: setup | ||
setup: | ||
@cp Web/appsettings.Development.json.template Web/appsettings.Development.json | ||
@echo "Please update Web/appsettings.Development.json for your local development" | ||
@echo "Your .env now is" | ||
@echo "================" | ||
@cat Web/appsettings.Development.json | ||
@echo "================" | ||
@echo "Please choose either docker-based or localhost setup before starting server" | ||
@echo "export NO_DOCKER=1 and replace Database part in ConnectionStrings.DataContext to 'localhost,1433' in Web/appsettings.Development.json if you use local development" | ||
@$(MAKE) db-setup | ||
|
||
|
||
.PHONY: db-setup | ||
db-setup: | ||
$(DOCKER_COMPOSE_CMD) up -d db | ||
@echo "IMPORTANT: You need to set up the database by using Data-application Wizard. Use the Database project by Azure Data Studio on Mac or Visual Studio on Windows to finish the setup." | ||
@echo "Check https://docs.microsoft.com/en-us/sql/azure-data-studio/extensions/sql-database-project-extension?view=sql-server-ver15" | ||
@echo "TODO: Automate database setup" | ||
|
||
.PHONY: dev | ||
dev: | ||
if [ "${NO_DOCKER}" = "" ]; then \ | ||
$(DOCKER_COMPOSE_CMD) up; \ | ||
else \ | ||
make -f Makefile.nodocker.mk dev; \ | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
DOCKER_COMPOSE_CMD := docker-compose -f docker-compose.dev.yml | ||
|
||
.PHONY: dev | ||
dev: | ||
make -C $(MODULE) dev | ||
|
||
.PHONY: docker-start-db | ||
docker-start-db: | ||
$(DOCKER_COMPOSE_CMD) up -d db | ||
|
||
.PHONY: docker-stop-db | ||
docker-stop-db: | ||
$(DOCKER_COMPOSE_CMD) stop db |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,5 @@ | ||
# Ignore output of pre-build target | ||
wwwroot/css/**/*.css | ||
|
||
# Development settings | ||
appsettings.Development.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
CONTAINER := web | ||
PROJECT_NAME = Web | ||
PORT = 3000 | ||
|
||
include ../shared.mk |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"Logging": { | ||
"LogLevel": { | ||
"Default": "Debug" | ||
} | ||
}, | ||
"ConnectionStrings": { | ||
"DataContext": "Server=db,1433; User Id=SA; Password=veryStrongSecret!; Database=Database; Trusted_Connection=False; MultipleActiveResultSets=true" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
version: '3.4' | ||
|
||
volumes: | ||
db_data: {} | ||
|
||
services: | ||
web: | ||
image: ${DOCKER_REGISTRY-}web | ||
build: | ||
context: . | ||
dockerfile: ./Dockerfile.dev | ||
environment: | ||
- ASPNETCORE_ENVIRONMENT=Development | ||
- NO_DOCKER=1 | ||
ports: | ||
- "3000:3000" | ||
command: make dev MODULE=Web PORT=3000 | ||
volumes: | ||
- ./Web:/src/Web | ||
|
||
|
||
db: | ||
image: mcr.microsoft.com/azure-sql-edge | ||
user: root | ||
ports: | ||
- 1433:1433 | ||
environment: | ||
ACCEPT_EULA: 'true' | ||
SA_PASSWORD: veryStrongSecret! | ||
volumes: | ||
- db_data:/var/opt/mssql:delegated |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
SELF_DIR := $(dir $(lastword $(MAKEFILE_LIST))) | ||
|
||
CONTAINER ?= | ||
|
||
PROJECT_NAME ?= | ||
PORT ?= | ||
|
||
DOCKER_COMPOSE_CMD := docker-compose -f $(SELF_DIR)docker-compose.dev.yml | ||
|
||
ifeq (,${NO_DOCKER}) | ||
DOCKER_RUN := $(DOCKER_COMPOSE_CMD) run -w /src/$(PROJECT_NAME) --rm ${CONTAINER} | ||
else | ||
DOCKER_RUN := | ||
endif | ||
|
||
.PHONY: vendor | ||
vendor: | ||
@echo "Installing dependency..." | ||
$(DOCKER_RUN) dotnet restore | ||
$(DOCKER_RUN) dotnet list $(PROJECT_NAME).csproj package | ||
|
||
.PHONY: dev | ||
dev: vendor | ||
$(DOCKER_RUN) dotnet watch run --urls "http://*:$(PORT)" | ||
|
||
.PHONY: dist | ||
dist: vendor | ||
$(DOCKER_RUN) dotnet publish -c Release -o dist |