Skip to content

Commit

Permalink
Merge pull request #8 from MZC-CSC/main
Browse files Browse the repository at this point in the history
Unification of the overall project call structure and modification of load test operation method.
  • Loading branch information
MZC-CSC authored Jul 22, 2024
2 parents b7d2d47 + c471533 commit 7ae88ee
Show file tree
Hide file tree
Showing 85 changed files with 8,214 additions and 5,520 deletions.
4 changes: 3 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,6 @@ ant
.DS_Store
meta/*.db
result/**
data/**
data/**
conf/**
container-volume/**
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@ result/**
**.properties
meta/*.db
ant
data/**
data/**
conf/**
container-volume/**
16 changes: 13 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
# Stage 1: Build the Ant app
FROM golang:1.21.6-alpine AS builder

RUN apk add --no-cache make gcc sqlite-libs sqlite-dev build-base
ARG TARGETOS=linux
ARG TARGETARCH=amd64

RUN apk add --no-cache make

WORKDIR /go/src/github.com/cloud-barista/cm-ant

Expand All @@ -11,11 +14,14 @@ RUN go mod download

COPY . .

RUN CGO_ENABLED=1 GOOS=linux GOARCH=amd64 make build
RUN CGO_ENABLED=0 GOOS=$TARGETOS GOARCH=$TARGETARCH make build


# Stage 2: Run the Ant app
FROM alpine:latest as prod
FROM ubuntu:22.04 as prod

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

# ANT ROOT PATH
ENV ANT_ROOT_PATH=/app
Expand All @@ -29,6 +35,10 @@ 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
COPY --from=builder /go/src/github.com/cloud-barista/cm-ant/web /app/web

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


EXPOSE 8880

ENTRYPOINT ["./ant"]
150 changes: 145 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,10 +1,150 @@
###########################################################
ANT_NETWORK=cm-ant-network
DB_CONTAINER_NAME=ant-postgres
DB_NAME=cm-ant-db
DB_USER=cm-ant-user
DB_PASSWORD=cm-ant-secret

ANT_CONTAINER_NAME=cm-ant
OS := $(shell uname -s | tr '[:upper:]' '[:lower:]')
ARCH := $(shell uname -m)

ifeq ($(ARCH),x86_64)
ARCH := amd64
else ifeq ($(ARCH),arm64)
ARCH := arm64
else ifeq ($(ARCH),aarch64)
ARCH := arm64
endif
###########################################################

###########################################################
.PHONY: swag
swag:
swag init -g cmd/cm-ant/main.go --output api/
@swag init -g cmd/cm-ant/main.go --output api/
###########################################################

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

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

###########################################################
.PHONY: create-network
create-network:
@if [ -z "$$(docker network ls -f name=$(ANT_NETWORK))" ]; then \
echo "Creating cm-ant network..."; \
docker network create --driver bridge $(ANT_NETWORK); \
echo "cm-ant network created!"; \
else \
echo "cm-ant network already exist..."; \
fi
###########################################################

###########################################################
.PHONY: run-db
run-db: create-network
@if [ -z "$$(docker ps -q -f name=$(DB_CONTAINER_NAME))" ]; then \
echo "Run database container...."; \
docker container run \
--name $(DB_CONTAINER_NAME) \
--network $(ANT_NETWORK) \
-p 5432:5432 \
-e POSTGRES_USER=$(DB_USER) \
-e POSTGRES_PASSWORD=$(DB_PASSWORD) \
-e POSTGRES_DB=$(DB_NAME) \
-d --rm \
timescale/timescaledb:latest-pg16; \
echo "Started Postgres database container!"; \
echo "Waiting for database to be ready..."; \
for i in $$(seq 1 10); do \
docker exec $(DB_CONTAINER_NAME) pg_isready -U $(DB_USER) -d $(DB_NAME); \
if [ $$? -eq 0 ]; then \
echo "Database is ready!"; \
break; \
fi; \
echo "Database is not ready yet. Waiting..."; \
sleep 5; \
done; \
if [ $$i -eq 10 ]; then \
echo "Failed to start the database"; \
exit 1; \
fi; \
echo "Database $(DB_NAME) successfully started!"; \
else \
echo "Database container is already running."; \
fi
###########################################################

###########################################################
.PHONY: down
down: down-container image-remove
@echo "Checking if the database container is running..."
@if [ -n "$$(docker 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: swag run build
###########################################################
.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 7ae88ee

Please sign in to comment.