-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Able to run grate programmatically (#417)
* - applying dotnet format * - moving current grate to src\grate.console project * - restructure the current grate base on the proposal * - rename grate to grate.core and grate.console to grate (prevent the breaking change in publish artifact) * - adding more test case and remove unuse namespace * - add DependencyInjectionRegistrationExtensions * - cleanup code and restructure to the right place for unit test * - remove the IFactory, using MS DI instead. * chore(unuse imports) * - remove the target framework in build.props to load the TFM successfully. * - fix the grate command. * - add UT for service collection. * - adding more UT and change to IDbConnection instead of DbConnection. * - fix overriding method * - Remove database type and masterDatabase in IGrateTestContext, using static instead. * - update the docker build and its example * - add k8s with init container and multi-tenancy example * - adding more comment into grate builder * - fix Ut error related to set table casing * update grate docs * - add grate nuget package publishing * - Add NuGet.md into package * -chore(code format) * - update code comment * - fix github workflow ident for push nuget package * - add symbols for source link
- Loading branch information
1 parent
43d45e5
commit 225220b
Showing
225 changed files
with
2,964 additions
and
856 deletions.
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
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
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,5 +1,4 @@ | ||
#!/bin/env pwsh | ||
|
||
# App versioning is normally provided by your CI/CD pipelines... | ||
docker-compose build --build-arg APP_VERSION=0.0.1 | ||
docker-compose up |
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 @@ | ||
INSERT INTO grate_test(name) VALUES ('Hello grate from docker !'); |
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,4 @@ | ||
CREATE TABLE grate_test ( | ||
id int IDENTITY(1,1) NOT NULL PRIMARY KEY, | ||
name nvarchar(255) NOT NULL | ||
) |
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,16 +1,24 @@ | ||
version: "3.7" | ||
services: | ||
db-migration: | ||
build: . | ||
image: myapp-dbmigration | ||
#build: . | ||
image: erikbra/grate:latest | ||
environment: | ||
# don't configure passwords here for real. This is just a sample! | ||
- APP_CONNSTRING="Server=db;Database=grate_test;User Id=sa;Password=gs8j4AS7h87jHg" | ||
|
||
APP_CONNSTRING: "Server=db;Database=grate_test;User Id=sa;Password=gs8j4AS7h87jHg;TrustServerCertificate=True" | ||
VERSION: "1.0.0.0" | ||
DATABASE_TYPE: "sqlserver" # sqlite, oracle, postgresql, sqlserver, mariadb | ||
volumes: | ||
- ./db:/db | ||
- ./output:/output | ||
|
||
depends_on: | ||
- db | ||
db: | ||
image: mcr.microsoft.com/mssql/server:2019-latest | ||
environment: | ||
- SA_PASSWORD=gs8j4AS7h87jHg # again, plain text passwords are bad mmkay! | ||
- ACCEPT_EULA=Y | ||
- MSSQL_PID=Express | ||
- MSSQL_PID=Express | ||
ports: | ||
- "1433:1433" |
This file was deleted.
Oops, something went wrong.
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 @@ | ||
* |
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 |
---|---|---|
@@ -0,0 +1,18 @@ | ||
FROM mcr.microsoft.com/dotnet/sdk:8.0-alpine AS build | ||
WORKDIR . | ||
|
||
COPY sample-service/ ./sample-service/ | ||
RUN dotnet publish ./sample-service/*.csproj -c release -o ./publish/app | ||
|
||
FROM mcr.microsoft.com/dotnet/aspnet:8.0-alpine as runtime | ||
WORKDIR /app | ||
|
||
COPY --from=build /publish/app . | ||
|
||
# Add globalization support to the OS so .Net can use cultures | ||
RUN apk add icu-libs | ||
ENV DOTNET_SYSTEM_GLOBALIZATION_INVARIANT=false | ||
ENV ASPNETCORE_URLS=http://[::]:80 | ||
ENV ASPNETCORE_ENVIRONMENT=Production | ||
|
||
ENTRYPOINT ["dotnet", "sample-service.dll"] |
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,11 @@ | ||
FROM erikbra/grate:latest as base | ||
WORKDIR /app | ||
COPY sql/ /db | ||
RUN mkdir /output | ||
ENTRYPOINT ./grate \ | ||
--sqlfilesdirectory=/db \ | ||
--version=$VERSION \ | ||
--connstring="$APP_CONNSTRING" \ | ||
--silent \ | ||
--databasetype=sqlserver \ | ||
--outputPath=/output |
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,42 @@ | ||
## Grate with k8s | ||
|
||
You can propably run grate on your production environment using k8s init container. Please see the very basic example how to config and deploy to k8s. | ||
|
||
## Prerequisite: | ||
|
||
Local k8s simulator: you can use [minikube](https://github.com/kubernetes/minikube) (my favorite) or [kind](https://github.com/kubernetes-sigs/kind) | ||
|
||
## Usage | ||
|
||
Now let's get started with your terminal (any Linux dist, MacOS or WSL2): | ||
- Open your terminal and start minikube | ||
|
||
```sh | ||
minikube start | ||
``` | ||
|
||
- Apply the deployment | ||
|
||
```sh | ||
kubectl apply -f deployment.yaml | ||
``` | ||
- You can check the status with command | ||
```sh | ||
kubectl get pods -w | grep grate | ||
``` | ||
- After the pod started, let's test the data :D | ||
```sh | ||
kubectl port-forward svc/grate-k8s 5000:5000 | ||
# sending the http request | ||
curl -sL http://localhost:5000/api/grate | jq | ||
``` | ||
- Done. Remember to destroy the cluster | ||
```sh | ||
minikube stop | ||
``` | ||
## Notes | ||
- Curious how it works, see the `Dockerfile` and `Dockerfile-db`. | ||
Oops, something went wrong.