Skip to content

Commit

Permalink
Merge pull request #14 from MZC-CSC/main
Browse files Browse the repository at this point in the history
Refactor API Functions, Introduce Price Collector, and Update Documents
  • Loading branch information
MZC-CSC authored Sep 2, 2024
2 parents 1bc9c03 + 444791f commit 4a66d0a
Show file tree
Hide file tree
Showing 17 changed files with 1,034 additions and 1,281 deletions.
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ RUN CGO_ENABLED=0 GOOS=$TARGETOS GOARCH=$TARGETARCH make build
FROM ubuntu:22.04 as prod

Check warning on line 24 in Dockerfile

View workflow job for this annotation

GitHub Actions / Publish a container image

The 'as' keyword should match the case of the 'from' keyword

FromAsCasing: 'as' and 'FROM' keywords' casing do not match More info: https://docs.docker.com/go/dockerfile/rule/from-as-casing/

RUN apt update && \
apt install -y sudo curl
apt install -y sudo curl rsync

# ANT ROOT PATH
ENV ANT_ROOT_PATH=/app
Expand All @@ -38,7 +38,7 @@ COPY --from=builder /go/src/github.com/cloud-barista/cm-ant/script /app/script
COPY --from=builder /go/src/github.com/cloud-barista/cm-ant/meta /app/meta

HEALTHCHECK --interval=10s --timeout=5s --start-period=10s \
CMD curl -f "http://cm-ant:8880/ant/api/v1/readyz" || exit 1
CMD curl -f "http://localhost:8880/ant/api/v1/readyz" || exit 1


EXPOSE 8880
Expand Down
77 changes: 12 additions & 65 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
###########################################################
ANT_NETWORK=cm-ant-network
DB_CONTAINER_NAME=ant-postgres
ANT_NETWORK=cm-ant-local-net
DB_CONTAINER_NAME=ant-local-postgres
DB_NAME=cm-ant-db
DB_USER=cm-ant-user
DB_PASSWORD=cm-ant-secret
Expand All @@ -24,22 +24,22 @@ swag:
@swag init -g cmd/cm-ant/main.go --output api/
###########################################################

###########################################################
.PHONY: run
run: run-db
@go run cmd/cm-ant/main.go
###########################################################

###########################################################
.PHONY: build
build:
@go build -o ant ./cmd/cm-ant/...
###########################################################

###########################################################
.PHONY: run
run: run-db
@go run cmd/cm-ant/main.go
###########################################################

###########################################################
.PHONY: create-network
create-network:
@if [ -z "$$(docker network ls -f name=$(ANT_NETWORK))" ]; then \
@if [ -z "$$(docker network ls -q -f name=$(ANT_NETWORK))" ]; then \
echo "Creating cm-ant network..."; \
docker network create --driver bridge $(ANT_NETWORK); \
echo "cm-ant network created!"; \
Expand All @@ -51,7 +51,7 @@ create-network:
###########################################################
.PHONY: run-db
run-db: create-network
@if [ -z "$$(docker ps -q -f name=$(DB_CONTAINER_NAME))" ]; then \
@if [ -z "$$(docker container ps -q -f name=$(DB_CONTAINER_NAME))" ]; then \
echo "Run database container...."; \
docker container run \
--name $(DB_CONTAINER_NAME) \
Expand Down Expand Up @@ -85,66 +85,13 @@ run-db: create-network

###########################################################
.PHONY: down
down: down-container image-remove
down:
@echo "Checking if the database container is running..."
@if [ -n "$$(docker ps -q -f name=$(DB_CONTAINER_NAME))" ]; then \
@if [ -n "$$(docker container ps -q -f name=$(DB_CONTAINER_NAME))" ]; then \
echo "Stopping and removing the database container..."; \
docker container stop $(DB_CONTAINER_NAME); \
echo "Database container stopped!"; \
else \
echo "No running database container found."; \
fi
###########################################################

###########################################################
.PHONY: image-remove
image-remove:
@if [ -n "$$(docker images -q $(ANT_CONTAINER_NAME):latest)" ]; then \
echo "Image $(ANT_CONTAINER_NAME):latest exists. Removing now..."; \
docker image rm $(ANT_CONTAINER_NAME):latest; \
else \
echo "Image $(ANT_CONTAINER_NAME):latest does not exist. Skipping removal."; \
fi
###########################################################

###########################################################
.PHONY: image-build
image-build:
@if [ -z "$$(docker images -q cm-ant:latest)" ]; then \
echo "Image $(ANT_CONTAINER_NAME):latest does not exist. Building now..."; \
docker image build --build-arg TARGETOS=$(OS) --build-arg TARGETARCH=$(ARCH) --tag $(ANT_CONTAINER_NAME):latest --file Dockerfile .; \
else \
echo "Image $(ANT_CONTAINER_NAME):latest already exists. Skipping build."; \
fi
###########################################################

###########################################################
.PHONY: up
up: run-db image-build
@if [ -z "$$(docker ps -q -f name=$(ANT_CONTAINER_NAME))" ]; then \
echo "Run cm-ant application container...."; \
docker container run \
--name $(ANT_CONTAINER_NAME) \
--network $(ANT_NETWORK) \
-p 8880:8880 \
-e ANT_DATABASE_HOST=ant-postgres \
-d --rm \
$(ANT_CONTAINER_NAME):latest; \
echo "Started cm-ant application container!"; \
else \
echo "cm-ant application container is already running."; \
fi
###########################################################

###########################################################
.PHONY: down-container
down-container:
@echo "Checking if the cm-ant application container is running..."
@if [ -n "$$(docker ps -q -f name=$(ANT_CONTAINER_NAME))" ]; then \
echo "Stopping and removing the cm-ant application container..."; \
docker container stop $(ANT_CONTAINER_NAME); \
echo "cm-ant application container stopped!"; \
else \
echo "No running cm-ant application container found."; \
fi
###########################################################
Loading

0 comments on commit 4a66d0a

Please sign in to comment.