From 76cc7cea699c7acc593a9121d34d129f37be1940 Mon Sep 17 00:00:00 2001 From: Senthil V S <309563+siliconsenthil@users.noreply.github.com> Date: Thu, 27 Aug 2020 15:43:26 +0530 Subject: [PATCH] [INFRA-660] Dockerized cloudlift (#20) * add Dockerfile to run tests in a consistent manner * fix service update test * update docker config * add Jenkinsfile * update Jenkinsfile * fix * improved jenkins file * fix * fix * fix * fix * fix * fix * fix * fix * fix * fix * fix * fix * fix * fix * fix * fix * fix * fix * fix * fix * fix working dirs * add git * add docker client * fix * review comments Co-authored-by: Bhavin Doshi --- .dockerignore | 10 ++++++++++ Dockerfile | 9 +++++++++ Jenkinsfile | 43 +++++++++++++++++++++++++++++++++++++++++++ Makefile | 6 +++++- README.md | 7 +++++++ 5 files changed, 74 insertions(+), 1 deletion(-) create mode 100644 .dockerignore create mode 100644 Dockerfile create mode 100644 Jenkinsfile diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 00000000..d6c7018e --- /dev/null +++ b/.dockerignore @@ -0,0 +1,10 @@ +.git +.gitignore +venv +*.egg-info +dist +Dockerfile +build +.pytest_cache +**/__pycache__ +**/*.pyc \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..87cfc608 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,9 @@ +FROM python:3.7.7-slim +RUN apt-get update && apt-get install make git docker.io -y +WORKDIR /cloudlift-bin +COPY requirements.txt . +RUN pip install -r requirements.txt +COPY . . +RUN pip install -e . +WORKDIR /workspace +ENTRYPOINT ["cloudlift"] \ No newline at end of file diff --git a/Jenkinsfile b/Jenkinsfile new file mode 100644 index 00000000..3f8d63e7 --- /dev/null +++ b/Jenkinsfile @@ -0,0 +1,43 @@ +pipeline { + agent { + label 'dockerbuild' + } + options { disableConcurrentBuilds() } + stages { + stage("Tag Cloudlift") { + steps { + println params + sh ''' + git remote set-url origin git@github.com:Rippling/cloudlift || git remote add origin git@github.com:Rippling/cloudlift + if ! [ -z "${COMMIT_ID}" ]; then + echo "Checking out custom commit id: ${COMMIT_ID}" + git checkout ${COMMIT_ID} + fi + git fetch --prune origin "+refs/tags/*:refs/tags/*" + echo "Tagging this commit: $(git rev-parse HEAD)" + git tag ${TAG} + git push origin refs/tags/${TAG} + echo "List of git tag:\n$(git tag -l)" + ''' + } + } + + stage("Build Docker Image") { + steps { + sh ''' + docker build -t cloudlift:${TAG} . + ''' + } + } + + stage('Push to ECR') { + steps { + sh ''' + aws ecr get-login-password --region ${AWS_DEFAULT_REGION} | docker login --username AWS --password-stdin ${AWS_RIPPLING_ACCOUNT} + docker tag cloudlift:${TAG} ${AWS_RIPPLING_ACCOUNT}/cloudlift-repo:${TAG} + docker push ${AWS_RIPPLING_ACCOUNT}/cloudlift-repo:${TAG} + ''' + } + } + } +} diff --git a/Makefile b/Makefile index ef40dd3e..c56e0064 100644 --- a/Makefile +++ b/Makefile @@ -6,6 +6,9 @@ clean: test-template: python3 -m pytest test/deployment/service_template_generator_test.py -vv +test-unit: + pytest -s test/deployment/* + test-integration: pytest -s test/test_cloudlift.py @@ -24,4 +27,5 @@ install-test-package: package-upload: package python3 -m twine upload dist/* - +package-docker: + docker build -t cloudlift . \ No newline at end of file diff --git a/README.md b/README.md index e9121a53..72a74009 100644 --- a/README.md +++ b/README.md @@ -242,6 +242,13 @@ To run high level integration tests pytest -s test/test_cloudlift.py ``` +To run tests inside docker container + +```sh +docker build -t cloudlift . +docker run -it cloudlift +``` + This tests expects to have an access to AWS console. Since there's no extensive test coverage, it's better to manually test the impacted areas whenever there's a code change.