Skip to content

Commit

Permalink
chore: update make file and docker files
Browse files Browse the repository at this point in the history
  • Loading branch information
martinsaporiti committed Aug 1, 2024
1 parent 2817cab commit d30b10d
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 146 deletions.
1 change: 1 addition & 0 deletions .env-issuer.sample
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ ISSUER_LOG_LEVEL=-4
ISSUER_LOG_MODE=2
ISSUER_API_AUTH_USER=user-issuer
ISSUER_API_AUTH_PASSWORD=password-issuer
ISSUER_ENVIRONMENT=local

# --------------------------------------------------------------------------------
# KMS configuration
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM golang:1.21 as base
FROM golang:1.21 AS base
ARG VERSION
WORKDIR /service
ENV GOBIN /service/bin
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile-kms-importer
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM golang:1.21 as base
FROM golang:1.21 AS base
ARG VERSION

ARG ISSUER_KMS_ETH_PROVIDER_AWS_ACCESS_KEY
Expand Down
136 changes: 31 additions & 105 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
include .env-api
include .env-issuer
BIN := $(shell pwd)/bin
VERSION ?= $(shell git rev-parse --short HEAD)
Expand All @@ -13,7 +12,7 @@ DOCKER_COMPOSE_FILE := $(LOCAL_DEV_PATH)/docker-compose.yml
DOCKER_COMPOSE_FILE_INFRA := $(LOCAL_DEV_PATH)/docker-compose-infra.yml
DOCKER_COMPOSE_CMD := docker compose -p issuer -f $(DOCKER_COMPOSE_FILE)
DOCKER_COMPOSE_INFRA_CMD := docker compose -p issuer -f $(DOCKER_COMPOSE_FILE_INFRA)
ENVIRONMENT := ${ISSUER_API_ENVIRONMENT}
ENVIRONMENT := ${ISSUER_ENVIRONMENT}

ISSUER_KMS_PROVIDER_LOCAL_STORAGE_FILE_PATH := ${ISSUER_KMS_PROVIDER_LOCAL_STORAGE_FILE_PATH}
ISSUER_KMS_ETH_PROVIDER := ${ISSUER_KMS_ETH_PROVIDER}
Expand Down Expand Up @@ -55,61 +54,44 @@ $(BIN)/oapi-codegen: tools.go go.mod go.sum ## install code generator for API fi
api: $(BIN)/oapi-codegen
$(BIN)/oapi-codegen -config ./api/config-oapi-codegen.yaml ./api/api.yaml > ./internal/api/api.gen.go


.PHONY: api-ui
api-ui: $(BIN)/oapi-codegen
$(BIN)/oapi-codegen -config ./api_ui/config-oapi-codegen.yaml ./api_ui/api.yaml > ./internal/api_ui/api.gen.go

# If you want to use vault as a KMS provider, you need to run this command
.PHONY: up
up:
$(DOCKER_COMPOSE_INFRA_CMD) up -d redis postgres vault

# If you want to use localstorage as a KMS provider, you need to run this command
.PHONY: up/localstorage
up/localstorage:
$(DOCKER_COMPOSE_INFRA_CMD) up -d redis postgres

.PHONY: run
run:
$(eval DELETE_FILE = $(shell if [ -f ./.env-ui ]; then echo "false"; else echo "true"; fi))
@if [ -f ./.env-ui ]; then echo "false"; else touch ./.env-ui; fi
@if [ -f ./resolvers_settings.yaml ]; then echo "true"; else touch ./resolvers_settings.yaml; fi
COMPOSE_DOCKER_CLI_BUILD=1 DOCKER_FILE="Dockerfile" $(DOCKER_COMPOSE_CMD) up -d api pending_publisher
@if [ $(DELETE_FILE) = "true" ] ; then rm ./.env-ui; fi



.PHONY: run-arm
run-arm:
@echo "WARN: Running ARM version is deprecated. 'make run' will be executed instead."
@make run

.PHONY: run-ui
run-ui: add-host-url-swagger
@if [ -f ./resolvers_settings.yaml ]; then echo "true"; else touch ./resolvers_settings.yaml; fi
COMPOSE_DOCKER_CLI_BUILD=1 DOCKER_FILE="Dockerfile" $(DOCKER_COMPOSE_CMD) up -d api-ui ui notifications pending_publisher

.PHONY: run-ui-arm
run-ui-arm: add-host-url-swagger
@echo "WARN: Running ARM version is deprecated. 'make run-ui' will be executed instead."
@make run-ui

# Build the docker image for the issuer-api
.PHONY: build
build:
COMPOSE_DOCKER_CLI_BUILD=1 DOCKER_FILE="Dockerfile" $(DOCKER_COMPOSE_CMD) build api pending_publisher

.PHONY: build-arm
build-arm:
@echo "WARN: Running ARM version is deprecated. 'make build' will be executed instead."
@make build
docker build -t issuer-api:local -f ./Dockerfile .

# Build the docker image for the issuer-ui
.PHONY: build-ui
build-ui:
COMPOSE_DOCKER_CLI_BUILD=1 DOCKER_FILE="Dockerfile" $(DOCKER_COMPOSE_CMD) build api-ui ui notifications pending_publisher
docker build -t issuer-ui:local -f ./ui/Dockerfile ./ui

# Run the api, pending_publisher and notifications services
.PHONY: run
run:
@if [ -f ./resolvers_settings.yaml ]; then \
COMPOSE_DOCKER_CLI_BUILD=1 $(DOCKER_COMPOSE_CMD) up -d api pending_publisher notifications; \
else \
echo "./resolvers_settings.yaml not found"; \
fi

.PHONY: build-ui-arm
build-ui-arm:
@echo "WARN: Running ARM version is deprecated. 'make build-ui' will be executed instead."
@make build-ui
# Run the ui, api, pending_publisher and notifications services
# First build the ui image and the api image
.PHONY: run-ui
run-ui: build-ui build add-host-url-swagger
@if [ -f ./resolvers_settings.yaml ]; then \
COMPOSE_DOCKER_CLI_BUILD=1 $(DOCKER_COMPOSE_CMD) up -d ui api pending_publisher notifications; \
else \
echo "./resolvers_settings.yaml not found"; \
fi

.PHONY: down
down:
Expand All @@ -125,6 +107,7 @@ stop:
up-test:
$(DOCKER_COMPOSE_INFRA_CMD) up -d test_postgres vault test_local_files_apache

# Clean the vault data
.PHONY: clean-vault
clean-vault:
rm -R infrastructure/local/.vault/data/init.out
Expand Down Expand Up @@ -156,12 +139,6 @@ lint: $(BIN)/golangci-lint
lint-fix: $(BIN)/golangci-lint
$(BIN)/golangci-lint run --fix

# usage: make private_key=xxx add-private-key
.PHONY: add-private-key
add-private-key:
docker exec issuer-vault-1 \
vault write iden3/import/pbkey key_type=ethereum private_key=$(private_key)

## Usage:
## AWS: make private_key=XXX aws_access_key=YYY aws_secret_key=ZZZ aws_region=your-region import-private-key-to-kms
## localstorage and vault: make private_key=XXX import-private-key-to-kms
Expand Down Expand Up @@ -210,67 +187,12 @@ add-vault-token:
@echo ISSUER_KEY_STORE_TOKEN=$(TOKEN) >> .env-issuer.tmp
mv .env-issuer.tmp .env-issuer


.PHONY: run-initializer
run-initializer:
@if [ -f ./resolvers_settings.yaml ]; then echo "true"; else touch ./resolvers_settings.yaml; fi
COMPOSE_DOCKER_CLI_BUILD=1 DOCKER_FILE="Dockerfile" $(DOCKER_COMPOSE_CMD) up -d initializer
sleep 5

.PHONY: generate-issuer-did
generate-issuer-did: run-initializer
docker logs issuer-initializer-1
$(eval DID = $(shell docker logs -f --tail 1 issuer-initializer-1 | grep "did"))
@echo $(DID)
sed '/ISSUER_API_UI_ISSUER_DID/d' .env-api > .env-api.tmp
@echo ISSUER_API_UI_ISSUER_DID=$(DID) >> .env-api.tmp
mv .env-api.tmp .env-api
docker stop issuer-initializer-1
docker rm issuer-initializer-1


.PHONY: generate-issuer-did-arm
generate-issuer-did-arm:
@echo "WARN: Running ARM version is deprecated. 'make generate-issuer-did' will be executed instead."
@make generate-issuer-did

.PHONY: add-host-url-swagger
add-host-url-swagger:
@if [ $(ENVIRONMENT) != "" ] && [ $(ENVIRONMENT) != "local" ]; then \
sed -i -e "s#server-url = [^ ]*#server-url = \""${ISSUER_API_UI_SERVER_URL}"\"#g" api_ui/spec.html; \
fi

.PHONY: rm-issuer-imgs
rm-issuer-imgs: stop
$(DOCKER_COMPOSE_CMD) rm -f
docker rmi -f issuer-api issuer-ui issuer-api-ui issuer-pending_publisher

.PHONY: restart-ui
restart-ui: rm-issuer-imgs up run run-ui

.PHONY: restart-ui-arm
restart-ui-arm:
@echo "WARN: Running ARM version is deprecated. 'make restart-ui' will be executed instead."
@make restart-ui

.PHONY: print-did
print-did:
docker exec issuer-vault-1 \
vault kv get -mount=kv did

# use this to delete the did from vault. It will not be deleted from the database
.PHONY: delete-did
delete-did:
docker exec issuer-vault-1 \
vault kv delete kv/did

# use this to add the did to vault. It will not be added to the database
# usage: make did=xxx add-did
.PHONY: add-did
add-did:
docker exec issuer-vault-1 \
vault kv put kv/did did=$(did)

# usage: make vault_token=xxx vault-export-keys
.PHONY: vault-export-keys
vault-export-keys:
Expand All @@ -288,4 +210,8 @@ vault-import-keys:
.PHONY: change-vault-password
change-vault-password:
docker exec issuer-vault-1 \
vault write auth/userpass/users/issuernode password=$(new_password)
vault write auth/userpass/users/issuernode password=$(new_password)

.PHONY: print-commands
print-commands:
@grep '^\s*\.[a-zA-Z_][a-zA-Z0-9_]*' Makefile
45 changes: 6 additions & 39 deletions infrastructure/local/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,20 @@ version: "3.9"
services:

ui:
build:
context: ../../ui/
dockerfile: Dockerfile
image: issuer-ui:local
ports:
- "8088:80"
env_file:
- ../../.env-api
- ../../.env-ui
healthcheck:
test: [ "CMD", "curl", "-f", "host.docker.internal:8088/health" ]
test: [ "CMD", "curl", "-f", "localhost:8088/health" ]
interval: 10s
timeout: 5s
retries: 5

api:
build:
context: ../../
dockerfile: ${DOCKER_FILE}
image: issuer-api:local
ports:
- "3001:3001"
env_file:
Expand All @@ -28,32 +24,14 @@ services:
volumes:
- ../../localstoragekeys:/localstoragekeys:rw
healthcheck:
test: [ "CMD", "curl", "-f", "host.docker.internal:3001/status" ]
test: [ "CMD", "curl", "-f", "localhost:3001/status" ]
interval: 10s
timeout: 5s
retries: 5
command: sh -c "apk add curl && sleep 4s && ./migrate && ./platform"

api-ui:
build:
context: ../../
dockerfile: ${DOCKER_FILE}
ports:
- "3002:3002"
env_file:
- ../../.env-api
- ../../.env-issuer
healthcheck:
test: [ "CMD", "curl", "-f", "host.docker.internal:3002/status" ]
interval: 10s
timeout: 5s
retries: 5
command: sh -c "apk add curl && sleep 4s && ./migrate && ./platform_ui"

notifications:
build:
context: ../../
dockerfile: ${DOCKER_FILE}
image: issuer-api:local
ports:
- "3004:3004"
env_file:
Expand All @@ -62,25 +40,14 @@ services:
command: sh -c "sleep 4s && ./notifications"

pending_publisher:
build:
context: ../../
dockerfile: ${DOCKER_FILE}
image: issuer-api:local
ports:
- "3005:3005"
env_file:
- ../../.env-api
- ../../.env-issuer
command: sh -c "sleep 4s && ./pending_publisher"

initializer:
build:
context: ../../
dockerfile: ${DOCKER_FILE}
env_file:
- ../../.env-api
- ../../.env-issuer
command: sh -c "sleep 4s && ./migrate && ./issuer_initializer"

networks:
default:
name: issuer-network

0 comments on commit d30b10d

Please sign in to comment.