Skip to content

Instantly share code, notes, and snippets.

# 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"
@jinhduong
jinhduong / .gitlab-ci.yml
Last active August 14, 2018 15:43
Gitlab CICD
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 July 24, 2018 08:47
aspnetcore authorization
namespace Demo.WebApi.Controllers
{
// SIMPLE AUTHORIZATION
[Authorize]
[Route("api/[controller]")]
public class AccountController : Controller
{
public AccountController()
{
}
version: '2'
services:
sandbox.web:
build:
context: .
args:
env: sandbox
ports:
- "8080:80"
app.web:
worker_processes 1;
events {
worker_connections 1024;
}
http {
server {
listen 80;
server_name localhost;
{
// ...
"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",
},
// ...
export const environment = {
production: true,
config: {
host: 'https://api.xxx.xxx/api'
// more config
}
};
version: '3'
services:
staging.api:
build: .
ports:
- "5000:80"
environment:
- ASPNETCORE_ENVIRONMENT=Staging
production.api:
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
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();
}