Skip to content

Commit

Permalink
feat: Add CI/CD workflow.
Browse files Browse the repository at this point in the history
Pipeline
  • Loading branch information
gary-van-woerkens authored Nov 23, 2020
2 parents d971734 + adf664d commit e319f8a
Show file tree
Hide file tree
Showing 16 changed files with 1,179 additions and 1 deletion.
6 changes: 6 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.git
.github
.k8s
*.md
**/node_modules
**/.next/cache
3 changes: 3 additions & 0 deletions .github/renovate.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": ["github>SocialGouv/renovate-config:light"]
}
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
.next
out
out
node_modules
54 changes: 54 additions & 0 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
include:
- project: SocialGouv/gitlab-ci-yml
file: /autodevops.yml
ref: v17.13.0

variables:
AUTO_DEVOPS_RELEASE_AUTO: "🔖"
AUTO_DEVOPS_PRODUCTION_AUTO: "🚀"

# NOTE(douglasduteil): No install :(
# sharing the node_modules is too slow...
Install:
rules:
- when: never

Lint:
rules:
- when: never

Test:
rules:
- when: never

# NOTE(douglasduteil): use custom build job
# The website it statically built with Nextjs
# Here we manually run `yarn next export` and reuse the `out` dir in Dockerfile
Build:
needs: []
cache:
key:
files:
- yarn.lock
prefix: ${CI_JOB_NAME}
paths:
- .cache
script:
- yarn config set cache-folder $CI_PROJECT_DIR/.cache/yarn
- yarn --frozen-lockfile --prefer-offline
- yarn next build
- yarn next export
variables:
VERSION: ${CI_COMMIT_SHORT_SHA}
artifacts:
expire_in: 1 day
paths:
- out

# NOTE(julienbouquillon): use custom register job
# By default, kosko-charts use a "/app" for default docker images names
# TODO: discuss
Register image:
extends: .autodevops_register_image
variables:
IMAGE_NAME: $CI_REGISTRY_IMAGE/app
5 changes: 5 additions & 0 deletions .k8s/components/_namespace.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { createNamespace } from "@socialgouv/kosko-charts/utils/createNamespace";

const manifests = createNamespace();

export default manifests;
24 changes: 24 additions & 0 deletions .k8s/components/app.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import env from "@kosko/env"

import { create } from "@socialgouv/kosko-charts/components/app"

const manifests = create("app", {
env,
config: { containerPort: 3000 },
deployment: {
container: {
resources: {
requests: {
cpu: "50m",
memory: "128Mi",
},
limits: {
cpu: "200m",
memory: "256Mi",
},
},
},
},
})

export default manifests
32 changes: 32 additions & 0 deletions .k8s/environments/.gitlab-ci.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
CI_COMMIT_BEFORE_SHA=ae724d33b9dfe463812eb3890bba85c259a05e73
CI_COMMIT_BRANCH=beta-db-12
CI_COMMIT_DESCRIPTION=
CI_COMMIT_MESSAGE=build(k8s): add dummy drop-db job
CI_COMMIT_REF_NAME=beta-db-12
CI_COMMIT_REF_PROTECTED=false
CI_COMMIT_REF_SLUG=beta-db-12
CI_COMMIT_SHA=c58c0974f7023063b1296d3a5a285b46b92771f8
CI_COMMIT_TAG=xyz42
CI_COMMIT_SHORT_SHA=c58c0974
CI_COMMIT_TITLE=build(k8s): add dummy drop-db job
CI_ENVIRONMENT_NAME=beta-db-12-dev2
CI_ENVIRONMENT_SLUG=beta-db-12-dev2
CI_ENVIRONMENT_URL=https://beta-db-12-dev2-sample-next-app.dev2.fabrique.social.gouv.fr
CI_PROJECT_DIR=/builds/SocialGouv/sample-next-app
CI_PROJECT_ID=85
CI_PROJECT_NAME=sample-next-app
CI_PROJECT_NAMESPACE=SocialGouv
CI_PROJECT_PATH=SocialGouv/sample-next-app
CI_PROJECT_PATH_SLUG=socialgouv-sample-next-app
CI_PROJECT_REPOSITORY_LANGUAGES=javascript,shell,plpgsql,dockerfile,tsql
CI_PROJECT_TITLE=sample-next-app
CI_PROJECT_URL=https://gitlab.factory.social.gouv.fr/SocialGouv/sample-next-app
CI_PROJECT_VISIBILITY=public
CI_REGISTRY_IMAGE=registry.gitlab.factory.social.gouv.fr/socialgouv/sample-next-app
CI_REGISTRY_PASSWORD=[MASKED]
CI_REGISTRY_USER=gitlab-ci-token
KUBE_INGRESS_BASE_DOMAIN=dev2.fabrique.social.gouv.fr
KUBE_NAMESPACE=sample-next-app-85-beta-db-12-dev2
RANCHER_PROJECT_ID=c-f8qps:p-46tj7
ENABLE_AZURE_POSTGRES=1
AUTO_DEVOPS_DEV_ENVIRONMENT_NAME=-dev2
9 changes: 9 additions & 0 deletions .k8s/environments/dev/app.configmap.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
kind: ConfigMap
apiVersion: v1
metadata:
name: app-configmap
data:
NODE_ENV: "production"
PORT: "3000"
NEXT_PUBLIC_MATOMO_URL: "https://matomo.fabrique.social.gouv.fr/"
NEXT_PUBLIC_MATOMO_SITE_ID: "33"
9 changes: 9 additions & 0 deletions .k8s/environments/preprod/app.configmap.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
kind: ConfigMap
apiVersion: v1
metadata:
name: app-configmap
data:
NODE_ENV: "production"
PORT: "3000"
NEXT_PUBLIC_MATOMO_URL: "https://matomo.fabrique.social.gouv.fr/"
NEXT_PUBLIC_MATOMO_SITE_ID: "33"
9 changes: 9 additions & 0 deletions .k8s/environments/prod/app.configmap.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
kind: ConfigMap
apiVersion: v1
metadata:
name: app-configmap
data:
NODE_ENV: "production"
PORT: "3000"
NEXT_PUBLIC_MATOMO_URL: "https://matomo.fabrique.social.gouv.fr/"
NEXT_PUBLIC_MATOMO_SITE_ID: "33"
2 changes: 2 additions & 0 deletions .k8s/kosko.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
components = ["*"]
require = ["ts-node/register"]
34 changes: 34 additions & 0 deletions .k8s/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
const fs = require("fs");
const toml = require("toml");

const data = toml.parse(
fs.readFileSync(`${__dirname}/../socialgouv.toml`, "utf-8")
);
console.dir(data);

("use strict");

const env = require("@kosko/env");
const { generate, print, PrintFormat } = require("@kosko/generate");
const { join } = require("path");

(async () => {
// Set environment
env.env = "dev";

// Set CWD (Optional)
env.cwd = __dirname;

// Generate manifests
const result = await generate({
path: join(env.cwd, "components"),
components: ["*"],
baseEnvironment: "_base",
});

// Print manifests to stdout
print(result, {
format: PrintFormat.YAML,
writer: process.stdout,
});
})();
27 changes: 27 additions & 0 deletions .k8s/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"license": "Apache-2.0",
"scripts": {
"generate": "kosko generate",
"generate:dev": "kosko generate --env dev",
"generate:prod": "kosko generate --env prod",
"gitlab": "DOTENV_CONFIG_PATH=./environments/.gitlab-ci.env kosko generate --require dotenv/config",
"gitlab:dev": "yarn --silent gitlab --env dev",
"gitlab:preprod": "yarn --silent gitlab --env preprod",
"gitlab:prod": "yarn --silent gitlab --env prod",
"xxx": "DOTENV_CONFIG_PATH=./environments/.gitlab-ci.env npx ts-node --require dotenv/config ./main.js"
},
"dependencies": {
"@kosko/env": "^0.5.2",
"@socialgouv/kosko-charts": "^3.2.2",
"kubernetes-models": "^1.0.1",
"toml": "^3.0.0"
},
"devDependencies": {
"@kubernetes-models/sealed-secrets": "^1.0.1",
"@types/node": "^14.14.7",
"dotenv": "^8.2.0",
"kosko": "^0.9.2",
"ts-node": "^9.0.0",
"typescript": "^4.0.5"
}
}
11 changes: 11 additions & 0 deletions .k8s/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"compilerOptions": {
"baseUrl": ".",
"esModuleInterop": true,
"module": "commonjs",
"moduleResolution": "node",
"strict": true,
"target": "es2015",
"types": ["node"]
}
}
Loading

0 comments on commit e319f8a

Please sign in to comment.