Skip to content

Instantly share code, notes, and snippets.

View .gitlab-ci.yml
build_image:
image: docker:git
services:
- docker:dind
script:
# Login to Gitlab Registry
- docker login -u gitlab-ci-token -p $CI_BUILD_TOKEN registry.gitlab.com
# Build image
- docker build -t registry.gitlab.com/<username>/<repo-name>/<docker-name>:latest --build-arg env=sandbox --build-arg <SOME-ARG>=<VALUE> .
# Then push image
@jinhduong
jinhduong / AccountController.cs
Created Jul 24, 2018
aspnetcore authorization
View AccountController.cs
namespace Demo.WebApi.Controllers
{
// SIMPLE AUTHORIZATION
[Authorize]
[Route("api/[controller]")]
public class AccountController : Controller
{
public AccountController()
{
}
View docker-compose.yml
version: '2'
services:
sandbox.web:
build:
context: .
args:
env: sandbox
ports:
- "8080:80"
app.web:
View nginx.conf
worker_processes 1;
events {
worker_connections 1024;
}
http {
server {
listen 80;
server_name localhost;
View package.json
{
// ...
"scripts": {
"ng": "ng",
"start": "ng serve & gulp watch",
"serve": "ng serve --sourcemap=false --verbose",
"build:prod": "ng build --env=prod --prod --build-optimizer",
"build:sandbox": "ng build --env=sandbox ---prod --build-optimizer",
},
// ...
View Dockerfile
# The builder from node image
FROM node:alpine as builder
# build-time variables
# prod|sandbox its value will be come from outside
ARG env=prod
RUN apk update && apk add --no-cache make git
# Move our files into directory name "app"
View environment.prod.ts
export const environment = {
production: true,
config: {
host: 'https://api.xxx.xxx/api'
// more config
}
};
View docker-compose.yml
version: '3'
services:
staging.api:
build: .
ports:
- "5000:80"
environment:
- ASPNETCORE_ENVIRONMENT=Staging
production.api:
View Dockerfile
FROM microsoft/aspnetcore-build:2.0 AS build-env
WORKDIR /app
# Copy csproj and restore as distinct layers
COPY *.csproj ./
RUN dotnet restore
# Copy everything else and build
COPY . ./
RUN dotnet publish -c Release -o out
View Startup.cs
public partial class Startup
{
public Startup(IHostingEnvironment env)
{
var builder = new ConfigurationBuilder()
.SetBasePath(env.ContentRootPath)
.AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: false, reloadOnChange: true)
.AddEnvironmentVariables();
Configuration = builder.Build();
}