Skip to content

Commit

Permalink
Merge pull request #16 from MZC-CSC/develop
Browse files Browse the repository at this point in the history
minor changes for performance evaluation
  • Loading branch information
MZC-CSC authored Sep 27, 2024
2 parents afa5847 + 30404a2 commit dcd7db1
Show file tree
Hide file tree
Showing 21 changed files with 2,146 additions and 1,957 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,6 @@ ant
data
conf
container-volume
./bin/**
./bin/**

config.yaml
5 changes: 2 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ FROM golang:1.23.0-bookworm AS builder
ARG TARGETOS=linux
ARG TARGETARCH=amd64

RUN apt-get update && \
apt-get install -y --no-install-recommends make rsync && \
RUN apt-get update -y && \
apt-get install -y --no-install-recommends make rsync openssh-server ssh && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*

Expand Down Expand Up @@ -35,7 +35,6 @@ COPY --from=builder /go/src/github.com/cloud-barista/cm-ant/ant /app/ant
COPY --from=builder /go/src/github.com/cloud-barista/cm-ant/config.yaml /app/config.yaml
COPY --from=builder /go/src/github.com/cloud-barista/cm-ant/test_plan /app/test_plan
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://localhost:8880/ant/api/v1/readyz" || exit 1
Expand Down
82 changes: 81 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,23 @@
###########################################################
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

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:
Expand All @@ -12,6 +32,66 @@ build:

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

###########################################################
.PHONY: create-network
create-network:
@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!"; \
else \
echo "cm-ant network already exist..."; \
fi
###########################################################

###########################################################
.PHONY: run-db
run-db: create-network
@if [ -z "$$(docker container 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 container 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:
@echo "Checking if the database container is running..."
@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
###########################################################
2 changes: 1 addition & 1 deletion cmd/cm-ant/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
// @basePath /ant
func main() {

err := utils.Script(utils.JoinRootPathWith("/script/install_rsync.sh"), []string{})
err := utils.Script(utils.JoinRootPathWith("/script/install_required_utils.sh"), []string{})
if err != nil {
log.Fatal("required tool can not install")
}
Expand Down
2 changes: 1 addition & 1 deletion docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ services:
restart: unless-stopped

cb-tumblebug:
image: cloudbaristaorg/cb-tumblebug:0.9.11
image: cloudbaristaorg/cb-tumblebug:0.9.13
container_name: cb-tumblebug
platform: linux/amd64
ports:
Expand Down
57 changes: 57 additions & 0 deletions internal/core/load/authorized_key_checker.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package load

import (
"fmt"
"os"
"strings"

"github.com/cloud-barista/cm-ant/internal/utils"
)

// getAddAuthorizedKeyCommand returns a command to add the authorized key.
func getAddAuthorizedKeyCommand(pkName, pubkName string) (string, error) {
pubKeyPath, _, err := validateKeyPair(pkName, pubkName)
if err != nil {
return "", err
}

pub, err := utils.ReadToString(pubKeyPath)
if err != nil {
return "", err
}

addAuthorizedKeyScript := utils.JoinRootPathWith("/script/add-authorized-key.sh")

addAuthorizedKeyCommand, err := utils.ReadToString(addAuthorizedKeyScript)
if err != nil {
return "", err
}

addAuthorizedKeyCommand = strings.Replace(addAuthorizedKeyCommand, `PUBLIC_KEY=""`, fmt.Sprintf(`PUBLIC_KEY="%s"`, pub), 1)
return addAuthorizedKeyCommand, nil
}

// validateKeyPair checks and generates SSH key pair if it doesn't exist.
func validateKeyPair(pkName, pubkName string) (string, string, error) {
homeDir, err := os.UserHomeDir()
if err != nil {
return "", "", err
}

privKeyPath := fmt.Sprintf("%s/.ssh/%s", homeDir, pkName)
pubKeyPath := fmt.Sprintf("%s/.ssh/%s", homeDir, pubkName)

err = utils.CreateFolderIfNotExist(fmt.Sprintf("%s/.ssh", homeDir))
if err != nil {
return pubKeyPath, privKeyPath, err
}

exist := utils.ExistCheck(privKeyPath)
if !exist {
err := utils.GenerateSSHKeyPair(4096, privKeyPath, pubKeyPath)
if err != nil {
return pubKeyPath, privKeyPath, err
}
}
return pubKeyPath, privKeyPath, nil
}
Loading

0 comments on commit dcd7db1

Please sign in to comment.