From e7fa2a65897063b6eafcf2222ab908f66808b291 Mon Sep 17 00:00:00 2001 From: Piotr Biernat Date: Fri, 2 Dec 2022 22:05:47 +0100 Subject: [PATCH] initial --- .drone.yml | 36 ++++++++++++++++++++++++++++++++++++ Dockerfile | 17 +++++++++++++++++ Makefile | 12 ++++++++++++ README.md | 3 +++ api-registry/etc/server.json | 14 ++++++++++++++ deploy/image-build.sh | 16 ++++++++++++++++ deploy/image-push.sh | 7 +++++++ 7 files changed, 105 insertions(+) create mode 100644 .drone.yml create mode 100644 Dockerfile create mode 100644 Makefile create mode 100644 README.md create mode 100644 api-registry/etc/server.json create mode 100755 deploy/image-build.sh create mode 100755 deploy/image-push.sh diff --git a/.drone.yml b/.drone.yml new file mode 100644 index 0000000..6218503 --- /dev/null +++ b/.drone.yml @@ -0,0 +1,36 @@ +kind: pipeline +type: docker +name: default + +steps: +- name: publish_image + image: plugins/docker + environment: + DOCKER_USERNAME: + from_secret: registry_username + DOCKER_PASSWORD: + from_secret: registry_password + commands: + - sleep 5 + - ./deploy/image-build.sh + - ./deploy/image-push.sh + volumes: + - name: docker-sock + path: /var/run + when: + branch: + - main + +services: +- name: docker + image: docker:dind + privileged: true + volumes: + - name: docker-sock + path: /var/run + +volumes: +- name: gopath + temp: {} +- name: docker-sock + temp: {} diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..47a3ccc --- /dev/null +++ b/Dockerfile @@ -0,0 +1,17 @@ +FROM hashicorp/consul:1.14 + +LABEL dev.egommerce.image.author="Piotr Biernat" +LABEL dev.egommerce.image.vendor="Egommerce" +LABEL dev.egommerce.image.service="api-registry" +LABEL dev.egommerce.image.version="1.0" + +COPY ./api-registry/etc /consul/config + +RUN cat /usr/local/bin/docker-entrypoint.sh +EXPOSE 8500 8600 8600/udp +# USER consul + +ENTRYPOINT ["consul", "agent", "-config-dir=/consul/config"] + +# CMD ["consul", "agent", "-config-dir=/consul/config"] +# ENTRYPOINT ["docker-entrypoint.sh"] diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..1b190e9 --- /dev/null +++ b/Makefile @@ -0,0 +1,12 @@ +DEPLOY_DIR := ./deploy +SRC_DIR := ./src + +## DEPLOY PART +build-image-dev: + - sh ${DEPLOY_DIR}/image-build.sh dev + +build-image-prod: + - sh ${DEPLOY_DIR}/image-build.sh + +push-image-prod: + - sh ${DEPLOY_DIR}/image-push.sh diff --git a/README.md b/README.md new file mode 100644 index 0000000..f345c70 --- /dev/null +++ b/README.md @@ -0,0 +1,3 @@ +# api-registry + +API Registry - based on Consul diff --git a/api-registry/etc/server.json b/api-registry/etc/server.json new file mode 100644 index 0000000..ba08340 --- /dev/null +++ b/api-registry/etc/server.json @@ -0,0 +1,14 @@ +{ + "node_name": "api-registry", + "server": true, + "bootstrap" : true, + "ui_config": { + "enabled" : true + }, + "data_dir": "/consul/data", + "addresses": { + "http" : "0.0.0.0" + }, + "bind_addr": "0.0.0.0", + "advertise_addr": "127.0.0.1" +} \ No newline at end of file diff --git a/deploy/image-build.sh b/deploy/image-build.sh new file mode 100755 index 0000000..54a4d58 --- /dev/null +++ b/deploy/image-build.sh @@ -0,0 +1,16 @@ +#!/bin/sh +# RUN IN REPO ROOT DIR !! + +export IMAGE_NAME="git.pbiernat.dev/egommerce/api-registry" + +TARGET=${1:-latest} + +echo "Building: $IMAGE_NAME:$TARGET" +if [ $TARGET = "dev" ] +then + docker build --rm --no-cache -t "$IMAGE_NAME:dev" . # >/dev/null 2>&1 +else + docker build --rm --cache-from "$IMAGE_NAME:$TARGET" -t "$IMAGE_NAME:$TARGET" . >/dev/null 2>&1 +fi + +echo "Done." diff --git a/deploy/image-push.sh b/deploy/image-push.sh new file mode 100755 index 0000000..5dfca8f --- /dev/null +++ b/deploy/image-push.sh @@ -0,0 +1,7 @@ +#!/bin/sh +# RUN IN REPO ROOT DIR !! + +export IMAGE_NAME="git.pbiernat.dev/egommerce/api-registry" + +echo $DOCKER_PASSWORD | docker login git.pbiernat.dev -u $DOCKER_USERNAME --password-stdin +docker push "$IMAGE_NAME:latest"