Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add multienv argocd #249

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ build
!lama_cleaner/app/build
dist/
lama_cleaner.egg-info/
models
27 changes: 9 additions & 18 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,30 +7,21 @@ FROM python:3.7.4-slim-buster

LABEL maintainer Loreto Parisi [email protected]

WORKDIR app
ENV CACHE_DIR=/app/models

WORKDIR /app

RUN apt-get update && apt-get install -y --no-install-recommends \
software-properties-common \
libsm6 libxext6 ffmpeg libfontconfig1 libxrender1 libgl1-mesa-glx \
curl \
npm
curl

# python requirements
COPY . .
COPY requirements.txt /etc/tmp/requirements.txt
RUN pip install -r /etc/tmp/requirements.txt

# nodejs
RUN npm install n -g && \
n lts
# yarn
RUN npm install -g yarn
# download LaMa model
RUN curl -o $CACHE_DIR/hub/checkpoints/big-lama.pt --create-dirs -LJO https://github.com/Sanster/models/releases/download/add_big_lama/big-lama.pt

# webapp
RUN cd lama_cleaner/app/ && \
yarn && \
yarn build

EXPOSE 8080
# python requirements
RUN pip install -r requirements.txt

CMD ["bash"]
CMD ["bash"]
154 changes: 154 additions & 0 deletions Jenkinsfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
pipeline {
environment {
APP="huspy-lama-cleaner-service"
ENV=environment(BRANCH_NAME)
AWS_PROFILE="huspy-tools"
ECR="151712667821.dkr.ecr.eu-central-1.amazonaws.com"
APP_VERSION="${ENV}_v${BUILD_NUMBER}_${GIT_COMMIT}"
}

agent {
kubernetes {
yaml """
kind: Pod
metadata:
annotations:
spec:
containers:
- name: kubectl
image: 016216169391.dkr.ecr.eu-central-1.amazonaws.com/kubectl:v1.23.3
imagePullPolicy: Always
command:
- cat
tty: true
- name: kaniko
image: gcr.io/kaniko-project/executor:debug
resources:
requests:
cpu: "2"
memory: "2Gi"
limits:
cpu: "4"
memory: "7Gi"
imagePullPolicy: Always
command:
- cat
tty: true
volumeMounts:
- name: docker-config
mountPath: /kaniko/.docker
- name: ecr-profile
mountPath: /root/.aws
volumes:
- name: docker-config
configMap:
name: docker-config
- name: ecr-profile
configMap:
name: ecr-profile
"""
}
}

stages {
stage("Build with Kaniko") {
when {
anyOf {
expression { BRANCH_NAME ==~ /(release.*|development|fix.*|feature.*|bug.*|main)/ }
}
}
steps {
container(name: 'kaniko') {
sh """
/kaniko/executor --dockerfile `pwd`/Dockerfile --context `pwd` --destination=${ECR}/${APP}:${APP_VERSION}
"""
}
}
}

stage("Update image in argocd") {
when {
anyOf {
expression { BRANCH_NAME ==~ /(release.*|development|fix.*|feature.*|bug.*|main)/ }
}
}
steps {
container(name: 'alpine') {
dir('huspy-services') {
git branch: 'main', credentialsId: 'yahiakhidr', url: 'https://github.com/huspy/huspy-services.git'
}
ENV = selectEnvironment(BRANCH_NAME)
sh """
apk add yq git
cd huspy-services
yq e -i '.microservice.image.tag = "${APP_VERSION}"' helm/${APP}/${ENV}.yaml
git config --global --add safe.directory ${WORKSPACE}/huspy-services
git config --global user.email "[email protected]"
git config --global user.name "github_actor"
git checkout main
git add helm/${APP}/${ENV}.yaml
git commit -m "Update ${APP} image in ${ENV}"
"""
withCredentials([gitUsernamePassword(credentialsId: 'yahiakhidr')]) {
dir('huspy-services') {
sh 'git push origin main'
}
}
}
}
}
}
}

def environment(branch) {
script {
if (branch ==~ /main|v\d+\.\d+\.\d+/) {
return "prod"
}
if (branch ==~ /feature.*|development|fix.*|bug.*/ ) {
return "dev"
}
if (branch ==~ /release.*/ ) {
return "qa"
}
}
}

def branchToConfig(branch) {
script {
result = "NULL"
if (branch == 'main') {
result = "production"
slackChannel = "alerts-prod-deployments"
echo "BRANCH:${branch} -> CONFIGURATION:${result}"
}
if (branch ==~ /feature.*|development|fix.*|bug.*/) {
result = "development"
slackChannel = "alerts-prod-deployments"
echo "BRANCH:${branch} -> CONFIGURATION:${result}"
}
if (branch ==~ /release.*/) {
result = "qa"
slackChannel = "alerts-prod-deployments"
echo "BRANCH:${branch} -> CONFIGURATION:${result}"
}
return result
}
}

def selectEnvironment(branch) {
script {
def dev_environments = 'feature/(dev|grey|purple|orange|blue)/.*'
def matcher = branch =~ dev_environments
if (matcher.find()) {
return matcher.group(1)
}
if (branch ==~ /release.*/) {
return "qa"
}
if (branch ==~ "master|main") {
return "prod"
}
}
return "dev"
}
33 changes: 33 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
version: "3.2"
services:
api:
container_name: lama-cleaner-flask-backend
build: .
ports:
- '8080:8080'
environment:
- CACHE_DIR=/app/models
command: python3 main.py --device=cpu --port=8080
restart: always
networks:
- default
client:
build:
context: lama_cleaner/app/
environment:
- REACT_APP_INPAINTING_URL=http://localhost:8080
- PROXY=http://api:8080
image: react-app-client
restart: always
command: yarn start
ports:
- "3000:3000"
networks:
- default
depends_on:
- api
volumes:
- ./lama_cleaner/app/:/client
networks:
default:
driver: bridge
12 changes: 12 additions & 0 deletions lama_cleaner/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Ignore everything:
**

# Except:
!public
!src
!.env
!.eslintrc.json
!.prettierrc
!package.json
!tsconfig.json
!yarn.lock
4 changes: 4 additions & 0 deletions lama_cleaner/app/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
FROM node:16.13.1-bullseye-slim
WORKDIR /client
COPY . .
RUN yarn install && yarn build
2 changes: 1 addition & 1 deletion lama_cleaner/parse_args.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

def parse_args():
parser = argparse.ArgumentParser()
parser.add_argument("--host", default="127.0.0.1")
parser.add_argument("--host", default="0.0.0.0")
parser.add_argument("--port", default=8080, type=int)
parser.add_argument("--model", default="lama", choices=["lama", "ldm", "zits", "mat", 'fcf'])
parser.add_argument("--device", default="cuda", type=str, choices=["cuda", "cpu"])
Expand Down