Skip to content

Commit

Permalink
feat: add werf
Browse files Browse the repository at this point in the history
  • Loading branch information
fredleger committed Nov 22, 2023
1 parent 36a64d0 commit e71df24
Show file tree
Hide file tree
Showing 14 changed files with 200 additions and 25 deletions.
66 changes: 66 additions & 0 deletions .github/workflows/werf.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
name: CI Workflow (werf)

on:
push:
branches:
- ci/werf

jobs:
build:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4
with:
submodules: recursive

- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_HUB_USERNAME }}
password: ${{ secrets.DOCKER_HUB_PASSWORD }}

- name: Install asdf
uses: asdf-vm/actions/[email protected]

- name: Install asdf plugins & packages
run: |
asdf plugin add werf https://github.com/MxNxPx/asdf-werf.git
asdf plugin update --all
asdf install
- name: Provision kind Kubernetes cluster
run: |
set -x
curl -Lo /tmp/kind https://kind.sigs.k8s.io/dl/v0.20.0/kind-linux-amd64
chmod +x /tmp/kind
cat <<EOF | /tmp/kind create cluster --config=-
kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
nodes:
- role: control-plane
kubeadmConfigPatches:
- |
kind: InitConfiguration
nodeRegistration:
kubeletExtraArgs:
node-labels: "ingress-ready=true"
extraPortMappings:
- containerPort: 80
hostPort: 80
protocol: TCP
- containerPort: 443
hostPort: 443
protocol: TCP
EOF
kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/main/deploy/static/provider/kind/deploy.yaml
sleep 30
kubectl wait --namespace ingress-nginx \
--for=condition=ready pod \
--selector=app.kubernetes.io/component=controller \
--timeout=90s
- name: Run make ci
run: |
make ci
6 changes: 6 additions & 0 deletions .helm/Chart.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
dependencies:
- name: mongodb
repository: https://charts.bitnami.com/bitnami
version: 12.1.31
digest: sha256:b90da663e31f67804e0b129d8ee67c6972c2ddcecbbcb18328dddcb997375f26
generated: "2023-11-05T14:39:15.867576+01:00"
12 changes: 12 additions & 0 deletions .helm/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
apiVersion: v2
name: conduit
description: A Helm chart for Conduit
type: application
version: 0.1.0
appVersion: 0.1.0

dependencies:
- name: mongodb
repository: https://raw.githubusercontent.com/bitnami/charts/pre-2022/bitnami
version: 11.2.0
condition: mongodb.enabled
Binary file added .helm/charts/mongodb-12.1.31.tgz
Binary file not shown.
24 changes: 24 additions & 0 deletions .helm/templates/deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: realworld
spec:
replicas: 1
selector:
matchLabels:
app: realworld
template:
metadata:
labels:
app: realworld
spec:
imagePullSecrets:
- name: registrysecret
containers:
- name: app
image: {{ .Values.werf.image.prod }}
ports:
- containerPort: 8000
env:
- name: MONGO_URI
value: mongodb://app:app@mongodb:27017/test
17 changes: 17 additions & 0 deletions .helm/templates/ingress.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: realworld
spec:
ingressClassName: nginx
rules:
- host: realworld-127-0-0-1.sslip.io
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: realworld
port:
number: 8000
10 changes: 10 additions & 0 deletions .helm/templates/service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
apiVersion: v1
kind: Service
metadata:
name: realworld
spec:
selector:
app: realworld
ports:
- name: http
port: 8000
22 changes: 22 additions & 0 deletions .helm/values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
mongodb:
fullnameOverride: mongodb
enabled: true
image:
tag: 4.4-debian-10
architecture: standalone
useStatefulSet: true
replicaCount: 1
auth:
enabled: true
username: app
password: app
database: test
readinessProbe:
enabled: false
livenessProbe:
enabled: false
# resources:
# requests:
# memory: 1Gi
# limits:
# memory: 1Gi
1 change: 1 addition & 0 deletions .tool-versions
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
werf 1.2.267
36 changes: 17 additions & 19 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,23 +1,25 @@
all: build ci publish

build: docker-build
ci: lint format unit-tests coverage functional-tests ci-clean
ci: lint format unit-tests coverage functional-tests
publish: docker-publish

lint:
bash scripts/lint.sh
WERF_RUN = werf run --docker-options="-i --rm --entrypoint=/bin/bash" dev

format:
bash scripts/format.sh
lint: docker-build
${WERF_RUN} -- -c "bash scripts/lint.sh"

pre-commit:
bash scripts/pre-commit.sh
format: docker-build
${WERF_RUN} -- -c "bash scripts/format.sh"

unit-tests:
bash scripts/unit-tests.sh
pre-commit: docker-build
echo "TO BE IMPLEMENTED"

coverage:
bash scripts/coverage.sh
unit-tests: docker-build
${WERF_RUN} -- -c "bash scripts/unit-tests.sh"

coverage: docker-build
${WERF_RUN} -- -c "bash scripts/coverage.sh"

functional-tests:
bash scripts/functional-tests.sh
Expand All @@ -26,13 +28,9 @@ ci-clean:
rm -rf .pytest_cache
rm -rf .mypy_cache

docker-build: docker-build-prod docker-build-dev

docker-build-prod:
docker build -t webofmars/cicdparadox:standard-latest --target=prod .

docker-build-dev:
docker build -t webofmars/cicdparadox:standard-develop --target=dev .
docker-build:
werf build --repo webofmars/cicdparadox

docker-publish: docker-build
docker push webofmars/cicdparadox:standard-latest
docker push webofmars/cicdparadox:latest-prod
docker push webofmars/cicdparadox:latest-dev
2 changes: 1 addition & 1 deletion realworld
12 changes: 8 additions & 4 deletions scripts/functional-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,20 @@
set -e

echo "Starting API stack"
docker compose up -d api
# NOTE: we do not use compose anymore since werf is k8s enabled
# instead resources will be deployed in our locla kubernetes cluster
werf converge --repo webofmars/cicdparadox

echo "Waiting for API container to be up"
bash scripts/wait-for-it.sh localhost:8000 --timeout=60 --strict -- echo "API is up"
bash scripts/wait-for-it.sh realworld-127-0-0-1.sslip.io:80 --timeout=60 --strict -- echo "API is up"
echo "Waiting for API to be healthy"
until curl --output /dev/null --silent --fail http://localhost:8000/health; do
until curl --output /dev/null --silent --fail http://realworld-127-0-0-1.sslip.io/health; do
printf '.'
sleep 5
done
echo ""
echo "API is healthy"

echo "Running functional tests"
bash scripts/test.sh
docker compose stop
werf dismiss --repo webofmars/cicdparadox
2 changes: 1 addition & 1 deletion scripts/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
set -e

SCRIPTDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )"
export APIURL=http://realworld-127-0-0-1.sslip.io:8000
export APIURL=http://realworld-127-0-0-1.sslip.io:80

USERNAME=${USERNAME:-u$(date +%s)}
EMAIL=${EMAIL:-$USERNAME@mail.com}
Expand Down
15 changes: 15 additions & 0 deletions werf.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
configVersion: 1
project: cicdparadox
---
image: prod
dockerfile: Dockerfile
target: prod
---
image: dev
dockerfile: Dockerfile
target: dev
dependencies:
- image: prod
imports:
- type: ImageName
targetBuildArg: BASE_IMAGE

0 comments on commit e71df24

Please sign in to comment.