From 19e30df574000e7ae31140414350feed895cdbd8 Mon Sep 17 00:00:00 2001 From: atanistra Date: Mon, 23 Apr 2018 10:17:53 +0200 Subject: [PATCH 01/27] fix default status code --- mock.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mock.py b/mock.py index f3bd67d..1790025 100644 --- a/mock.py +++ b/mock.py @@ -8,7 +8,7 @@ METHOD_NOT_ALLOWED_RESPONSE = { 'body': {'message': 'Method not implemented'}, 'headers': {'Content-Type': 'application/json'}, - 'status': 405 + 'status_code': 405 } From f2291ffbd0243f3338ce2fb4850eef17a538c2db Mon Sep 17 00:00:00 2001 From: atanistra Date: Mon, 23 Apr 2018 10:49:02 +0200 Subject: [PATCH 02/27] add examples --- endpoints.json => examples/endpoints.json | 0 {responses => examples/responses}/hello/get.json | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename endpoints.json => examples/endpoints.json (100%) rename {responses => examples/responses}/hello/get.json (100%) diff --git a/endpoints.json b/examples/endpoints.json similarity index 100% rename from endpoints.json rename to examples/endpoints.json diff --git a/responses/hello/get.json b/examples/responses/hello/get.json similarity index 100% rename from responses/hello/get.json rename to examples/responses/hello/get.json From 7522865b27ef54fb5612eb37ad2da499a4b98ea6 Mon Sep 17 00:00:00 2001 From: atanistra Date: Mon, 23 Apr 2018 10:49:23 +0200 Subject: [PATCH 03/27] docker-entrypoint --- ops/docker-entrypoint.sh | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100755 ops/docker-entrypoint.sh diff --git a/ops/docker-entrypoint.sh b/ops/docker-entrypoint.sh new file mode 100755 index 0000000..db0cc8a --- /dev/null +++ b/ops/docker-entrypoint.sh @@ -0,0 +1,26 @@ +#!/usr/bin/env bash + +set -ex + +function add_exec_user() { + if [ -z "${EXEC_USER_ID}" ] + then + EXEC_USER_ID=0 + fi + + if [ ${EXEC_USER_ID} == 0 ] + then + useradd -m -o -g 0 -u ${EXEC_USER_ID} exec_user + else + useradd -m -o -u ${EXEC_USER_ID} exec_user + fi +} + +id -u exec_user &> /dev/null || add_exec_user + +if [ "${1}" == "mock" ] +then + su ${EXEC_USER_NAME} -c "python3 /mock.py" +else + exec "$@" +fi From 47f29f856474cb1568bbbcb205d2682e32f86ff4 Mon Sep 17 00:00:00 2001 From: atanistra Date: Mon, 23 Apr 2018 10:49:46 +0200 Subject: [PATCH 04/27] packer file --- ops/mocky_packer.json | 62 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 ops/mocky_packer.json diff --git a/ops/mocky_packer.json b/ops/mocky_packer.json new file mode 100644 index 0000000..6939d45 --- /dev/null +++ b/ops/mocky_packer.json @@ -0,0 +1,62 @@ +{ + "variables": { + "workspace_dir": "{{env `WORKSPACE_DIR`}}", + "aws_registry": "{{env `DOCKER_REGISTRY`}}", + "aws_access_key": "{{env `AWS_ACCESS_KEY_ID`}}", + "aws_secret_key": "{{env `AWS_SECRET_ACCESS_KEY`}}", + "aws_profile": "{{env `AWS_PROFILE`}}" + }, + "builders": [ + { + "type": "docker", + "image": "python:3.6", + "commit": true, + "changes": [ + "LABEL maintainer=artsalliancemedia.com", + "ENV MOCK_WORKDIR=/mock", + "VOLUME /mock", + "WORKDIR /mock", + "ENTRYPOINT [\"/docker-entrypoint.sh\"]" + ] + } + ], + "provisioners": [ + { + "type": "file", + "source": "{{user `workspace_dir`}}/mock.py", + "destination": "/" + }, + { + "type": "file", + "source": "{{user `workspace_dir`}}/ops/docker-entrypoint.sh", + "destination": "/" + }, + { + "type": "file", + "source": "{{user `workspace_dir`}}/requirements.txt", + "destination": "/tmp/" + }, + { + "type": "shell", + "inline": [ + "pip3 install --upgrade -r /tmp/requirements.txt" + ] + } + ], + "post-processors": [ + [ + { + "type": "docker-tag", + "repository": "{{user `aws_registry`}}/aam_mocky", + "tag": "latest" + }, + { + "type": "docker-push", + "login": "true", + "aws_access_key": "{{user `aws_access_key`}}", + "aws_secret_key": "{{user `aws_secret_key`}}", + "aws_profile": "{{user `aws_secret_key`}}" + } + ] + ] +} From 4bc4c70360c3d2f5fb67e6181c052294b7641511 Mon Sep 17 00:00:00 2001 From: atanistra Date: Mon, 23 Apr 2018 10:50:29 +0200 Subject: [PATCH 05/27] update gitignore --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index 72364f9..9719cdf 100644 --- a/.gitignore +++ b/.gitignore @@ -87,3 +87,5 @@ ENV/ # Rope project settings .ropeproject + +.idea \ No newline at end of file From a04259925d28c2e5b9a71daaffdfa444f0cb9f6c Mon Sep 17 00:00:00 2001 From: atanistra Date: Mon, 23 Apr 2018 10:50:41 +0200 Subject: [PATCH 06/27] pipeline --- Jenkinsfile | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 Jenkinsfile diff --git a/Jenkinsfile b/Jenkinsfile new file mode 100644 index 0000000..052d3f2 --- /dev/null +++ b/Jenkinsfile @@ -0,0 +1,26 @@ +#!/usr/bin/env groovy + +pipeline { + agent { + label { + label 'docker' + } + } + options { + timestamps() + timeout(time: 30, unit: 'MINUTES') + } + environment { + AWS_ACCESS_KEY_ID = credentials('AAMDEV_AWS_ACCESS_KEY_ID') + AWS_SECRET_ACCESS_KEY = credentials('AAMDEV_AWS_SECRET_ACCESS_KEY') + AWS_PROFILE = "aamdevelopment" + DOCKER_REGISTRY = "${env.REPO_PREFIX}" + } + stages { + stage('Build docker image') { + steps { + sh 'make docker-build-mocky' + } + } + } +} \ No newline at end of file From 1770c16fedc74fdd3529da15dc7e7e7d9db988a1 Mon Sep 17 00:00:00 2001 From: atanistra Date: Mon, 23 Apr 2018 10:50:51 +0200 Subject: [PATCH 07/27] build image --- Makefile | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 Makefile diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..4cb8255 --- /dev/null +++ b/Makefile @@ -0,0 +1,6 @@ +export WORKSPACE_DIR:=$(shell pwd) + +PACKER?=packer.io + +docker-build-mocky: + $(PACKER) build ops/mocky_packer.json \ No newline at end of file From 4ffd5a9dbfc10416d9439a4aed46ce503973a4b2 Mon Sep 17 00:00:00 2001 From: atanistra Date: Mon, 23 Apr 2018 10:51:11 +0200 Subject: [PATCH 08/27] mock reqs --- requirements.txt | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 requirements.txt diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..a4581ba --- /dev/null +++ b/requirements.txt @@ -0,0 +1,2 @@ +flask +flask-restful \ No newline at end of file From d14e8dc701b9919f989ccbeb53a9d1cf7898477b Mon Sep 17 00:00:00 2001 From: atanistra Date: Mon, 23 Apr 2018 11:50:46 +0200 Subject: [PATCH 09/27] Update pipeline --- Jenkinsfile | 1 + Makefile | 4 ++++ ops/mocky_packer.json | 5 +++-- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 052d3f2..e8581b1 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -15,6 +15,7 @@ pipeline { AWS_SECRET_ACCESS_KEY = credentials('AAMDEV_AWS_SECRET_ACCESS_KEY') AWS_PROFILE = "aamdevelopment" DOCKER_REGISTRY = "${env.REPO_PREFIX}" + IMAGE_TAG = "${env.BRANCH_NAME} } stages { stage('Build docker image') { diff --git a/Makefile b/Makefile index 4cb8255..a3c8c50 100644 --- a/Makefile +++ b/Makefile @@ -2,5 +2,9 @@ export WORKSPACE_DIR:=$(shell pwd) PACKER?=packer.io +ifeq ($(IMAGE_TAG), master) +export IMAGE_TAG=latest +endif + docker-build-mocky: $(PACKER) build ops/mocky_packer.json \ No newline at end of file diff --git a/ops/mocky_packer.json b/ops/mocky_packer.json index 6939d45..9e51514 100644 --- a/ops/mocky_packer.json +++ b/ops/mocky_packer.json @@ -4,7 +4,8 @@ "aws_registry": "{{env `DOCKER_REGISTRY`}}", "aws_access_key": "{{env `AWS_ACCESS_KEY_ID`}}", "aws_secret_key": "{{env `AWS_SECRET_ACCESS_KEY`}}", - "aws_profile": "{{env `AWS_PROFILE`}}" + "aws_profile": "{{env `AWS_PROFILE`}}", + "tag": "{{env `IMAGE_TAG`}}" }, "builders": [ { @@ -47,7 +48,7 @@ [ { "type": "docker-tag", - "repository": "{{user `aws_registry`}}/aam_mocky", + "repository": "{{user `aws_registry`}}/{{user `tag`}}", "tag": "latest" }, { From 08062dffe7b229e3d3044bfa2ca4c8fe54f1e945 Mon Sep 17 00:00:00 2001 From: atanistra Date: Mon, 23 Apr 2018 14:10:57 +0200 Subject: [PATCH 10/27] fix --- Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index e8581b1..c1cb258 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -15,7 +15,7 @@ pipeline { AWS_SECRET_ACCESS_KEY = credentials('AAMDEV_AWS_SECRET_ACCESS_KEY') AWS_PROFILE = "aamdevelopment" DOCKER_REGISTRY = "${env.REPO_PREFIX}" - IMAGE_TAG = "${env.BRANCH_NAME} + IMAGE_TAG = "${env.BRANCH_NAME}" } stages { stage('Build docker image') { From f168160b91d1403203c56bc4101add548d38deec Mon Sep 17 00:00:00 2001 From: atanistra Date: Mon, 23 Apr 2018 14:27:16 +0200 Subject: [PATCH 11/27] update creds --- ops/mocky_packer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ops/mocky_packer.json b/ops/mocky_packer.json index 9e51514..2a3103e 100644 --- a/ops/mocky_packer.json +++ b/ops/mocky_packer.json @@ -56,7 +56,7 @@ "login": "true", "aws_access_key": "{{user `aws_access_key`}}", "aws_secret_key": "{{user `aws_secret_key`}}", - "aws_profile": "{{user `aws_secret_key`}}" + "aws_profile": "{{user `aws_profile`}}" } ] ] From 6e6b7c10fe73622281f713f13e4ce66b6a581234 Mon Sep 17 00:00:00 2001 From: atanistra Date: Mon, 23 Apr 2018 16:23:38 +0200 Subject: [PATCH 12/27] update tags --- ops/mocky_packer.json | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/ops/mocky_packer.json b/ops/mocky_packer.json index 2a3103e..b478c21 100644 --- a/ops/mocky_packer.json +++ b/ops/mocky_packer.json @@ -48,12 +48,11 @@ [ { "type": "docker-tag", - "repository": "{{user `aws_registry`}}/{{user `tag`}}", - "tag": "latest" + "repository": "{{user `aws_registry`}}/aam_mocky", + "tag": "{{user `tag`}}" }, { "type": "docker-push", - "login": "true", "aws_access_key": "{{user `aws_access_key`}}", "aws_secret_key": "{{user `aws_secret_key`}}", "aws_profile": "{{user `aws_profile`}}" From e7220b7699af263f85d9fd278c89bff012c081e9 Mon Sep 17 00:00:00 2001 From: atanistra Date: Mon, 23 Apr 2018 16:38:53 +0200 Subject: [PATCH 13/27] update pipeline --- Makefile | 1 + ops/mocky_packer.json | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index a3c8c50..7886a17 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,5 @@ export WORKSPACE_DIR:=$(shell pwd) +export IMAGE_TAG?=dev PACKER?=packer.io diff --git a/ops/mocky_packer.json b/ops/mocky_packer.json index b478c21..e645e00 100644 --- a/ops/mocky_packer.json +++ b/ops/mocky_packer.json @@ -53,9 +53,11 @@ }, { "type": "docker-push", + "ecr_login": true, "aws_access_key": "{{user `aws_access_key`}}", "aws_secret_key": "{{user `aws_secret_key`}}", - "aws_profile": "{{user `aws_profile`}}" + "aws_profile": "{{user `aws_profile`}}", + "login_server": "https://{{user `aws_registry`}}" } ] ] From 97a43aacae6a0f9f1d662f213e1e9919e694ceb5 Mon Sep 17 00:00:00 2001 From: atanistra Date: Mon, 23 Apr 2018 17:21:35 +0200 Subject: [PATCH 14/27] Add logging --- mock.py | 58 +++++++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 46 insertions(+), 12 deletions(-) diff --git a/mock.py b/mock.py index 1790025..948038b 100644 --- a/mock.py +++ b/mock.py @@ -11,6 +11,14 @@ 'status_code': 405 } +PREFLIGHT_RESPONSE = { + 'headers': {'Access-Control-Allow-Origin': '*', + 'Access-Control-Allow-Methods': 'POST, GET, PUT, DELETE, OPTIONS', + 'Access-Control-Allow-Headers': '*', + 'Access-Control-Max-Age': '86400'}, + 'status_code': 200 +} + def load_json(file_path): with open(file_path) as f: @@ -28,10 +36,12 @@ class MethodFile(Enum): POST = 'post.json' PUT = 'put.json' DELETE = 'delete.json' + OPTIONS = 'options.json' class Config: def __init__(self): + print(os.getcwd()) mock_workdir = os.getenv('MOCK_WORKDIR') mock_endpoints = os.getenv('MOCK_ENDPOINTS', 'endpoints.json') responses_dir_name = os.getenv('MOCK_RESPONSES_DIR_NAME', 'responses') @@ -43,44 +53,64 @@ def __init__(self): class FileResource(Resource): _response_file_path = None + _request_data = None + _method = None + _method_file = None def __init__(self, responses_path, endpoint_path): self._responses_path = responses_path self._endpoint_path = endpoint_path def get(self, **kwargs): - self._update_file_paths(MethodFile.GET, **kwargs) - self._save_request_data() + self._process_request(**kwargs) response = self._get_response() return response def post(self, **kwargs): - self._update_file_paths(MethodFile.POST, **kwargs) - self._save_request_data() + self._process_request(**kwargs) response = self._get_response() return response def put(self, **kwargs): - self._update_file_paths(MethodFile.PUT, **kwargs) + self._process_request(**kwargs) response = self._get_response() return response def delete(self, **kwargs): - self._update_file_paths(MethodFile.DELETE, **kwargs) + self._process_request(**kwargs) response = self._get_response() return response - def _save_request_data(self): + def options(self, **kwargs): + self._process_request(**kwargs) + response = self._get_response() + return response + + def _process_request(self, **kwargs): + self._method = request.method + self._method_file = MethodFile[self._method].value + self._extract_request_data() + self._update_file_paths(**kwargs) + self._log_request_data() + self._save_request_data() + + def _extract_request_data(self): request_data = { 'headers': dict(request.headers), 'body': request.json if request.is_json else request.data.decode() or None, 'args': dict(request.args), 'endpoint': request.endpoint, - 'method': request.method + 'method': self._method } - save_json(self._request_file_path, request_data) + self._request_data = request_data - def _update_file_paths(self, method, **kwargs): + def _save_request_data(self): + save_json(self._request_file_path, self._request_data) + + def _log_request_data(self): + app.logger.info("REQUEST: %s" % (self._request_data,)) + + def _update_file_paths(self, **kwargs): endpoint_path = self._endpoint_path for key, value in kwargs.items(): @@ -90,17 +120,21 @@ def _update_file_paths(self, method, **kwargs): else: endpoint_path = endpoint_path.replace(path_key, value) - self._response_file_path = os.path.join(self._responses_path, endpoint_path, method.value) + self._response_file_path = os.path.join(self._responses_path, endpoint_path, self._method_file) self._request_file_path = os.path.join(self._responses_path, 'last_request.json') def _get_response(self): try: response_data = load_json(self._response_file_path) except IOError: - response_data = METHOD_NOT_ALLOWED_RESPONSE + if self._method_file == MethodFile.OPTIONS.value: + response_data = PREFLIGHT_RESPONSE + else: + response_data = METHOD_NOT_ALLOWED_RESPONSE body = response_data.get('body') status_code = response_data.get('status_code') headers = response_data.get('headers') + app.logger.info("RESPONSE: %s" % (response_data,)) response = Response(json.dumps(body), status_code, headers) return response From 3af576f393c4d1cd03aeec16f82d93034178115d Mon Sep 17 00:00:00 2001 From: atanistra Date: Mon, 23 Apr 2018 17:21:50 +0200 Subject: [PATCH 15/27] more examples --- examples/endpoints.json | 4 +++- examples/responses/hello/alice/get.json | 5 +++++ examples/responses/hello/bob/get.json | 5 +++++ examples/responses/hello/world/__world_number__/get.json | 9 +++++++++ 4 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 examples/responses/hello/alice/get.json create mode 100644 examples/responses/hello/bob/get.json create mode 100644 examples/responses/hello/world/__world_number__/get.json diff --git a/examples/endpoints.json b/examples/endpoints.json index 8abea85..2f9790b 100644 --- a/examples/endpoints.json +++ b/examples/endpoints.json @@ -1,5 +1,7 @@ [ - "/hello" + "/hello", + "/hello/", + "/hello/world/<__world_number__>" ] diff --git a/examples/responses/hello/alice/get.json b/examples/responses/hello/alice/get.json new file mode 100644 index 0000000..fa6eae9 --- /dev/null +++ b/examples/responses/hello/alice/get.json @@ -0,0 +1,5 @@ +{ + "body": "Hello Alice!", + "status": 201, + "headers": {"Content-Type": "application/json"} +} diff --git a/examples/responses/hello/bob/get.json b/examples/responses/hello/bob/get.json new file mode 100644 index 0000000..f7be33a --- /dev/null +++ b/examples/responses/hello/bob/get.json @@ -0,0 +1,5 @@ +{ + "body": "Hello Bob!", + "status": 201, + "headers": {"Content-Type": "application/json"} +} diff --git a/examples/responses/hello/world/__world_number__/get.json b/examples/responses/hello/world/__world_number__/get.json new file mode 100644 index 0000000..430e7b8 --- /dev/null +++ b/examples/responses/hello/world/__world_number__/get.json @@ -0,0 +1,9 @@ +{ + "body": { + "World Number": 123 + }, + "status": 201, + "headers": { + "Content-Type": "application/json" + } +} From e8ed7290c13737b38cdae6058be31d70db70e51c Mon Sep 17 00:00:00 2001 From: atanistra Date: Mon, 23 Apr 2018 17:28:31 +0200 Subject: [PATCH 16/27] update docker registry --- Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index c1cb258..cee13c6 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -14,7 +14,7 @@ pipeline { AWS_ACCESS_KEY_ID = credentials('AAMDEV_AWS_ACCESS_KEY_ID') AWS_SECRET_ACCESS_KEY = credentials('AAMDEV_AWS_SECRET_ACCESS_KEY') AWS_PROFILE = "aamdevelopment" - DOCKER_REGISTRY = "${env.REPO_PREFIX}" + DOCKER_REGISTRY = "${env.KDMTS_REGISTRY}" IMAGE_TAG = "${env.BRANCH_NAME}" } stages { From 21965aa0347828fd88e8648a88fd462ac175d3ee Mon Sep 17 00:00:00 2001 From: atanistra Date: Tue, 24 Apr 2018 09:42:16 +0200 Subject: [PATCH 17/27] add region --- Jenkinsfile | 1 + 1 file changed, 1 insertion(+) diff --git a/Jenkinsfile b/Jenkinsfile index cee13c6..f4feb8c 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -14,6 +14,7 @@ pipeline { AWS_ACCESS_KEY_ID = credentials('AAMDEV_AWS_ACCESS_KEY_ID') AWS_SECRET_ACCESS_KEY = credentials('AAMDEV_AWS_SECRET_ACCESS_KEY') AWS_PROFILE = "aamdevelopment" + AWS_DEFAULT_REGION="eu-west-1" DOCKER_REGISTRY = "${env.KDMTS_REGISTRY}" IMAGE_TAG = "${env.BRANCH_NAME}" } From cddf54f2fb50f90fbca99159aee6af4d711112a4 Mon Sep 17 00:00:00 2001 From: atanistra Date: Tue, 24 Apr 2018 09:43:46 +0200 Subject: [PATCH 18/27] add region --- ops/mocky_packer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ops/mocky_packer.json b/ops/mocky_packer.json index e645e00..7642680 100644 --- a/ops/mocky_packer.json +++ b/ops/mocky_packer.json @@ -57,7 +57,7 @@ "aws_access_key": "{{user `aws_access_key`}}", "aws_secret_key": "{{user `aws_secret_key`}}", "aws_profile": "{{user `aws_profile`}}", - "login_server": "https://{{user `aws_registry`}}" + "login_server": "https://{{user `aws_registry`}}/" } ] ] From d5a6d96fe4cd744bc3677dfc60af10ed9e0f7267 Mon Sep 17 00:00:00 2001 From: atanistra Date: Tue, 24 Apr 2018 09:53:43 +0200 Subject: [PATCH 19/27] test --- ops/mocky_packer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ops/mocky_packer.json b/ops/mocky_packer.json index 7642680..7146230 100644 --- a/ops/mocky_packer.json +++ b/ops/mocky_packer.json @@ -57,7 +57,7 @@ "aws_access_key": "{{user `aws_access_key`}}", "aws_secret_key": "{{user `aws_secret_key`}}", "aws_profile": "{{user `aws_profile`}}", - "login_server": "https://{{user `aws_registry`}}/" + "login_server": "https://{{user `aws_registry`}}/aam_mocky" } ] ] From 59594403f539def2f34ff45c1072e662ef43d470 Mon Sep 17 00:00:00 2001 From: atanistra Date: Tue, 24 Apr 2018 09:55:39 +0200 Subject: [PATCH 20/27] test --- ops/mocky_packer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ops/mocky_packer.json b/ops/mocky_packer.json index 7146230..720a708 100644 --- a/ops/mocky_packer.json +++ b/ops/mocky_packer.json @@ -1,7 +1,7 @@ { "variables": { "workspace_dir": "{{env `WORKSPACE_DIR`}}", - "aws_registry": "{{env `DOCKER_REGISTRY`}}", + "aws_registry": "{{env `KDMTS_REGISTRY`}}", "aws_access_key": "{{env `AWS_ACCESS_KEY_ID`}}", "aws_secret_key": "{{env `AWS_SECRET_ACCESS_KEY`}}", "aws_profile": "{{env `AWS_PROFILE`}}", From e1fe13484b954e3f0fa17de2a915785ff7ca01eb Mon Sep 17 00:00:00 2001 From: atanistra Date: Tue, 24 Apr 2018 09:59:09 +0200 Subject: [PATCH 21/27] move ecr login to makefile --- Makefile | 9 ++++++++- ops/mocky_packer.json | 8 +------- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/Makefile b/Makefile index 7886a17..1513dc5 100644 --- a/Makefile +++ b/Makefile @@ -7,5 +7,12 @@ ifeq ($(IMAGE_TAG), master) export IMAGE_TAG=latest endif -docker-build-mocky: +ifdef AWS_PROFILE +export AWS_PROFILE_ARGS=--profile $(AWS_PROFILE) +endif + +docker-login-aws-ecr: + @$(shell aws ecr get-login --no-include-email --region eu-west-1 $(AWS_PROFILE_ARGS)) + +docker-build-mocky: docker-login-aws-ecr $(PACKER) build ops/mocky_packer.json \ No newline at end of file diff --git a/ops/mocky_packer.json b/ops/mocky_packer.json index 720a708..2776f6c 100644 --- a/ops/mocky_packer.json +++ b/ops/mocky_packer.json @@ -2,9 +2,6 @@ "variables": { "workspace_dir": "{{env `WORKSPACE_DIR`}}", "aws_registry": "{{env `KDMTS_REGISTRY`}}", - "aws_access_key": "{{env `AWS_ACCESS_KEY_ID`}}", - "aws_secret_key": "{{env `AWS_SECRET_ACCESS_KEY`}}", - "aws_profile": "{{env `AWS_PROFILE`}}", "tag": "{{env `IMAGE_TAG`}}" }, "builders": [ @@ -53,10 +50,7 @@ }, { "type": "docker-push", - "ecr_login": true, - "aws_access_key": "{{user `aws_access_key`}}", - "aws_secret_key": "{{user `aws_secret_key`}}", - "aws_profile": "{{user `aws_profile`}}", + "ecr_login": false, "login_server": "https://{{user `aws_registry`}}/aam_mocky" } ] From 30f5858c430df19762dc303a96abb6953304c57e Mon Sep 17 00:00:00 2001 From: atanistra Date: Tue, 24 Apr 2018 10:20:48 +0200 Subject: [PATCH 22/27] expose port --- ops/mocky_packer.json | 1 + 1 file changed, 1 insertion(+) diff --git a/ops/mocky_packer.json b/ops/mocky_packer.json index 2776f6c..31ca3cb 100644 --- a/ops/mocky_packer.json +++ b/ops/mocky_packer.json @@ -12,6 +12,7 @@ "changes": [ "LABEL maintainer=artsalliancemedia.com", "ENV MOCK_WORKDIR=/mock", + "EXPOSE 8080", "VOLUME /mock", "WORKDIR /mock", "ENTRYPOINT [\"/docker-entrypoint.sh\"]" From 2f5abf46bc8cbf0a3621309e991c43a3183257a0 Mon Sep 17 00:00:00 2001 From: atanistra Date: Tue, 24 Apr 2018 10:54:04 +0200 Subject: [PATCH 23/27] add cmd --- ops/mocky_packer.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ops/mocky_packer.json b/ops/mocky_packer.json index 31ca3cb..7dca6e4 100644 --- a/ops/mocky_packer.json +++ b/ops/mocky_packer.json @@ -15,7 +15,8 @@ "EXPOSE 8080", "VOLUME /mock", "WORKDIR /mock", - "ENTRYPOINT [\"/docker-entrypoint.sh\"]" + "ENTRYPOINT [\"/docker-entrypoint.sh\"]", + "CMD [\"mock\"]" ] } ], From 95298a742008ea0b00cc8ec2f17e32bf38fdfc01 Mon Sep 17 00:00:00 2001 From: atanistra Date: Tue, 24 Apr 2018 13:44:14 +0200 Subject: [PATCH 24/27] refactoring --- mock.py | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/mock.py b/mock.py index 948038b..f071c04 100644 --- a/mock.py +++ b/mock.py @@ -54,6 +54,7 @@ def __init__(self): class FileResource(Resource): _response_file_path = None _request_data = None + _response = None _method = None _method_file = None @@ -62,29 +63,28 @@ def __init__(self, responses_path, endpoint_path): self._endpoint_path = endpoint_path def get(self, **kwargs): - self._process_request(**kwargs) - response = self._get_response() - return response + self._process(**kwargs) + return self._response def post(self, **kwargs): - self._process_request(**kwargs) - response = self._get_response() - return response + self._process(**kwargs) + return self._response def put(self, **kwargs): - self._process_request(**kwargs) - response = self._get_response() - return response + self._process(**kwargs) + return self._response def delete(self, **kwargs): - self._process_request(**kwargs) - response = self._get_response() - return response + self._process(**kwargs) + return self._response def options(self, **kwargs): + self._process(**kwargs) + return self._response + + def _process(self, **kwargs): self._process_request(**kwargs) - response = self._get_response() - return response + self._response = self._get_response() def _process_request(self, **kwargs): self._method = request.method From 859e4b6cb385313af23430e6b632362039919b4e Mon Sep 17 00:00:00 2001 From: atanistra Date: Thu, 9 Aug 2018 10:26:52 +0200 Subject: [PATCH 25/27] fix exec user --- ops/docker-entrypoint.sh | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/ops/docker-entrypoint.sh b/ops/docker-entrypoint.sh index db0cc8a..8535b78 100755 --- a/ops/docker-entrypoint.sh +++ b/ops/docker-entrypoint.sh @@ -2,6 +2,8 @@ set -ex +export EXEC_USER_NAME=exec_user + function add_exec_user() { if [ -z "${EXEC_USER_ID}" ] then @@ -10,9 +12,9 @@ function add_exec_user() { if [ ${EXEC_USER_ID} == 0 ] then - useradd -m -o -g 0 -u ${EXEC_USER_ID} exec_user + useradd -m -o -g 0 -u ${EXEC_USER_ID} ${EXEC_USER_NAME} else - useradd -m -o -u ${EXEC_USER_ID} exec_user + useradd -m -o -u ${EXEC_USER_ID} ${EXEC_USER_NAME} fi } From 812e35b14fb94cfac347b7f316983441702b31c8 Mon Sep 17 00:00:00 2001 From: atanistra Date: Fri, 14 Sep 2018 14:31:30 +0200 Subject: [PATCH 26/27] fix file writing --- mock.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mock.py b/mock.py index f071c04..44f5128 100644 --- a/mock.py +++ b/mock.py @@ -27,7 +27,7 @@ def load_json(file_path): def save_json(file_path, data): - with open(file_path, 'w') as f: + with open(file_path, 'x') as f: json.dump(data, f) From b7b13bb03fe30b3486a0f4dd09fbe1d7342a236d Mon Sep 17 00:00:00 2001 From: atanistra Date: Fri, 14 Sep 2018 17:09:03 +0200 Subject: [PATCH 27/27] fix file writing --- mock.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mock.py b/mock.py index 44f5128..edb9988 100644 --- a/mock.py +++ b/mock.py @@ -27,7 +27,7 @@ def load_json(file_path): def save_json(file_path, data): - with open(file_path, 'x') as f: + with open(file_path, 'w+') as f: json.dump(data, f)