Skip to content

Commit

Permalink
Updates on files
Browse files Browse the repository at this point in the history
Added changeset on workflow
  • Loading branch information
Alexander Rogalskiy committed Aug 31, 2021
1 parent 4c821b6 commit 29fbb92
Show file tree
Hide file tree
Showing 27 changed files with 285 additions and 65 deletions.
File renamed without changes.
11 changes: 11 additions & 0 deletions .github/linters/.yaml-lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
# https://yamllint.readthedocs.io/en/stable/index.html
# yamllint --strict -c .github/linters/.yaml-lint.yml .

extends: default

rules:
document-start: disable
indentation: disable
line-length: disable
truthy: false
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,6 @@ site/
dist/
.cache
node_modules

# Env files
.env
2 changes: 1 addition & 1 deletion .husky/prepare-commit-msg
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

git cz --hook --non-interactive --type=feat --subject="added new features" || true
exec < /dev/tty && git cz --hook --non-interactive --type=feat --subject="added new features" || true
61 changes: 61 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
---
# https://pre-commit.com/
default_stages: [commit, push]
default_language_version:
# force all unspecified Python hooks to run python3
python: python3
minimum_pre_commit_version: "1.20.0"
repos:
- repo: meta
hooks:
- id: identity
- id: check-hooks-apply
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v3.4.0
hooks:
- id: check-added-large-files
- id: check-case-conflict
- id: check-executables-have-shebangs
exclude: ^scripts/windows\.sh$
- id: check-merge-conflict
- id: check-vcs-permalinks
# - id: check-yaml
- id: end-of-file-fixer
- id: fix-byte-order-marker
- id: mixed-line-ending
- id: trailing-whitespace
# - repo: https://github.com/Lucas-C/pre-commit-hooks
# rev: v1.1.10
# hooks:
# - id: forbid-tabs
# - id: remove-tabs
- repo: https://github.com/jumanjihouse/pre-commit-hooks
rev: 2.1.5
hooks:
- id: shellcheck
# - id: shfmt
- repo: https://github.com/codespell-project/codespell
rev: v2.0.0
hooks:
- id: codespell
name: Run codespell
description: Check Spelling with codespell
entry: codespell --ignore-words=codespell.txt
# - repo: https://github.com/igorshubovych/markdownlint-cli
# rev: v0.27.1
# hooks:
# - id: markdownlint
# name: Run markdownlint
# description: Checks the style of Markdown files
# entry: markdownlint -c .github/linters/.markdown-lint.yml .
# types: [markdown]
# files: \.(md|mdown|markdown)$
# - repo: https://github.com/adrienverge/yamllint
# rev: v1.26.1
# hooks:
# - id: yamllint
# name: Run yamllint
# description: Check YAML files with yamllint
# entry: yamllint --strict -c .github/linters/.yaml-lint.yml
# types: [yaml]
# files: \.(yaml|yml)$
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
##
## ---- Base OS layer ----
## docker build -t <container_tag> --build-arg IMAGE_SOURCE=node IMAGE_TAG=12-buster .
## docker build -t styled-scala-patterns --build-arg IMAGE_SOURCE=node --build-arg IMAGE_TAG=12-buster .
##
ARG IMAGE_SOURCE=node
ARG IMAGE_TAG=12-buster
Expand Down
55 changes: 55 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# Since we rely on paths relative to the makefile location, abort if make isn't being run from there.
$(if $(findstring /,$(MAKEFILE_LIST)),$(error Please only invoke this makefile from the directory it resides in))

IMAGE ?= styled-scala-patterns
TAG ?= latest

UTILS := docker tilt
# Make sure that all required utilities can be located.
UTIL_CHECK := $(or $(shell which $(UTILS) >/dev/null && echo 'ok'),$(error Did you forget to install `docker` and `tilt` after cloning the repo? At least one of the required supporting utilities not found: $(UTILS)))
DIRS := $(shell ls -d -- */ | grep -v public)

# Default target (by virtue of being the first non '.'-prefixed in the file).
.PHONY: _no-target-specified
_no-target-specified:
$(error Please specify the target to make - `make list` shows targets)

# Lists all targets defined in this makefile.
.PHONY: list
list:
@$(MAKE) -pRrn : -f $(MAKEFILE_LIST) 2>/dev/null | awk -v RS= -F: '/^# File/,/^# Finished Make data base/ {if ($$1 !~ "^[#.]") {print $$1}}' | command grep -v -e '^[^[:alnum:]]' -e '^$@$$command ' | sort

# Lists all dirs (except `public`).
.PHONY: dirs
dirs:
echo "$(DIRS)"

# Ensures that the git workspace is clean.
.PHONY: _ensure-clean
_ensure-clean:
@[ -z "$$((git status --porcelain --untracked-files=no || echo err) | command grep -v 'CHANGELOG.md')" ] || { echo "Workspace is not clean; please commit changes first." >&2; exit 2; }

# Run docker build command.
.PHONY: docker-build
docker-build: _ensure-clean
docker build -f Dockerfile -t $(IMAGE):$(TAG) .

# Run docker start command.
.PHONY: docker-start
docker-start:
docker-compose -f docker-compose.yml up -d

# Run docker stop command.
.PHONY: docker-stop
docker-stop:
docker-compose -f docker-compose.yml down -v --remove-orphans

# Run tilt start command.
.PHONY: tilt-start
tilt-start:
tilt up

# Run tilt stop command.
.PHONY: tilt-stop
tilt-stop:
tilt down --delete-namespaces
5 changes: 2 additions & 3 deletions Tiltfile
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ namespace_create('webapp')
conftest(path='k8s/backend/deployment.yaml', namespace='main')
# k8s_yaml('k8s/backend/deployment.yaml')
k8s_yaml(namespace_inject(read_file('k8s/backend/deployment.yaml'), 'webapp'), allow_duplicates=False)
k8s_resource('backend', port_forwards=8000, resource_deps=['deploy', 'conftest'])
k8s_resource('backend-scala-patterns-v1', port_forwards=8000, resource_deps=['deploy', 'conftest'])

# Records the current time, then kicks off a server update.
# Normally, you would let Tilt do deploys automatically, but this
Expand All @@ -32,9 +32,8 @@ local_resource(

# Add a live_update rule to our docker_build
congrats = "🎉 Congrats, you ran a live_update! 🎉"
docker_build_with_restart('scala-patterns', '.', build_args={'IMAGE_SOURCE': 'node', 'IMAGE_TAG': '12-buster'},
docker_build('styled-scala-patterns', '.', build_args={'IMAGE_SOURCE': 'node', 'IMAGE_TAG': '12-buster'},
dockerfile='./Dockerfile',
entrypoint=['mkdocs', 'serve', '--verbose', '--dirtyreload'],
live_update=[
sync('.', '/usr/src/app'),
run('python3 ./record-start-time.py'),
Expand Down
1 change: 1 addition & 0 deletions codespell.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
arbitrer
105 changes: 85 additions & 20 deletions k8s/backend/deployment.yaml
Original file line number Diff line number Diff line change
@@ -1,16 +1,55 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: backend-scala-patterns-configmap
namespace: webapp
labels:
app.kubernetes.io/name: backend-scala-patterns
app.kubernetes.io/instance: styled-scala-patterns
app.kubernetes.io/version: v1
app.kubernetes.io/component: function
app.kubernetes.io/part-of: serverless
app.kubernetes.io/managed-by: tilt
data:
SERVER_PORT: '8000'
APP_NAME: styled-scala-patterns
---
apiVersion: v1
kind: Service
metadata:
name: backend-scala-patterns
namespace: webapp
labels:
app.kubernetes.io/name: backend-scala-patterns
app.kubernetes.io/instance: styled-scala-patterns
app.kubernetes.io/version: v1
app.kubernetes.io/component: function
app.kubernetes.io/part-of: serverless
app.kubernetes.io/managed-by: tilt
spec:
type: ClusterIP
clusterIP: None
sessionAffinity: None
ports:
- name: http
protocol: TCP
port: 8000
selector:
app.kubernetes.io/name: backend-scala-patterns
app.kubernetes.io/version: v1
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: backend
name: backend-scala-patterns-v1
namespace: webapp
labels:
app.kubernetes.io/name: backend
app.kubernetes.io/instance: scala-patterns
app.kubernetes.io/version: '0.0.0'
app.kubernetes.io/component: backend
app.kubernetes.io/name: backend-scala-patterns
app.kubernetes.io/instance: styled-scala-patterns
app.kubernetes.io/version: v1
app.kubernetes.io/component: function
app.kubernetes.io/part-of: documentation
app.kubernetes.io/managed-by: tilt

spec:
replicas: 1
minReadySeconds: 60
Expand All @@ -23,23 +62,33 @@ spec:
type: RollingUpdate
selector:
matchLabels:
app: backend
app.kubernetes.io/name: backend-scala-patterns
app.kubernetes.io/version: v1
template:
metadata:
labels:
app: backend
app.kubernetes.io/name: backend-scala-patterns
app.kubernetes.io/version: v1
annotations:
scheduler.alpha.kubernetes.io/critical-pod: ''
spec:
dnsPolicy: Default
dnsPolicy: ClusterFirst
restartPolicy: Always
schedulerName: default-scheduler
terminationGracePeriodSeconds: 30
tolerations:
- key: 'CriticalAddonsOnly'
operator: 'Exists'
# tolerations:
# - key: "node-priority"
# operator: "Equal"
# value: "infra"
# effect: "NoExecute"
# nodeSelector:
# node-priority: infra
containers:
- name: backend
image: scala-patterns
- name: backend-scala-patterns
image: styled-scala-patterns
imagePullPolicy: IfNotPresent
terminationMessagePath: /etc/logs/termination.log
terminationMessagePolicy: File
ports:
- name: http
containerPort: 8000
Expand All @@ -53,16 +102,32 @@ spec:
valueFrom:
fieldRef:
fieldPath: metadata.name
- name: USER_AGENT
value: "k8s-agent $(WATCH_NAMESPACE)/$(POD_NAME)"
- name: LOG_DIR
value: "/tmp/logs"
volumeMounts:
- name: data
mountPath: /data
mountPath: "/data"
- name: data-tmp
mountPath: "/tmp"
resources:
limits:
cpu: 2000m
memory: 512Mi
requests:
cpu: 100m
memory: 32Mi
cpu: 1
memory: "2G"
ephemeral-storage: "2G"
limits:
cpu: 2
memory: "3G"
ephemeral-storage: "3G"
securityContext:
allowPrivilegeEscalation: false
allowPrivilegeEscalation: false
privileged: false
readOnlyRootFilesystem: false
runAsNonRoot: false
volumes:
- name: data
emptyDir: {}
- name: data-tmp
emptyDir: {}
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"remark": "remark -q -f .",
"commit": "git-cz",
"release": "release-it",
"name": "node ./scripts/rootAppName.js",
"format": "prettier --single-quote --write **/*.{json,yaml,yml}",
"format:md": "remark-preset-davidtheclark --format",
"format:check": "prettier --check **/*.{json,yaml,yml}",
Expand Down
5 changes: 3 additions & 2 deletions policy/deny.rego
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@ name = input.metadata.name

deny[msg] {
input.kind == "Deployment"
not input.spec.selector.matchLabels.app
not input.spec.selector.matchLabels.app.kubernetes.io/name
# not input.spec.selector.matchLabels.app

msg := "Containers must provide app label for pod selectors"
msg := "Containers must provide name/version label for pod selectors"
}

#deny[msg] {
Expand Down
3 changes: 1 addition & 2 deletions scripts/build-docs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ if [[ $STRICT_SCRIPT =~ $TRUE_REG ]]; then
fi

## Change working directory
BASE_DIR=$(dirname $0)/..
cd $BASE_DIR
cd "$(dirname "$0")" || exit 1

## Install pip module
wget --no-check-certificate https://bootstrap.pypa.io/get-pip.py -O $TMPDIR/get-pip.py
Expand Down
2 changes: 1 addition & 1 deletion scripts/create-changelog.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

set -u -e -o pipefail

cd ../
cd "$(dirname "$0")" || exit 1

VERSION=$(grep 'version:' package.json | sed -E "s/.*'([^']*)'/\1/")
RELEASE_DATE=$(date "+%Y-%m-%d")
Expand Down
9 changes: 9 additions & 0 deletions scripts/docker-build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/sh

set -e

cd "$(dirname "$0")" || exit 1

# Build docker images
GIT_SHA=$(git rev-parse HEAD)
docker build -f Dockerfile -t styled-scala-patterns -t styled-scala-patterns:$GIT_SHA --build-arg VERCEL_TOKEN=$1 .
8 changes: 8 additions & 0 deletions scripts/docker-compose-start.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/sh

set -e

cd "$(dirname "$0")" || exit 1

docker-compose -f docker-compose.yml build
docker-compose -f docker-compose.yml up -d
7 changes: 7 additions & 0 deletions scripts/docker-compose-stop.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/sh

set -e

cd "$(dirname "$0")" || exit 1

docker-compose -f docker-compose.yml down -v --remove-orphans
6 changes: 6 additions & 0 deletions scripts/installHusky.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
const {exec} = require('child_process');

exec(`husky install `, (err, stdout, stderr) => {
console.log(`stdout: ${stdout}`);
console.log(`stderr: ${stderr}`);
});

0 comments on commit 29fbb92

Please sign in to comment.