From 7666d4117d2182ecb13b736b68997c576d763b42 Mon Sep 17 00:00:00 2001 From: Flook Peter Date: Sat, 8 Jun 2024 11:36:23 +0800 Subject: [PATCH] Build for multiple archs, use ./data/service/persist folder to persist data --- .github/workflows/build.yaml | 4 +++- .gitignore | 2 ++ README.md | 3 ++- docker-compose.yaml | 27 +++++++++++++-------------- go.mod | 9 +++------ go.sum | 4 ++-- insta.go | 20 +++++++------------- 7 files changed, 32 insertions(+), 37 deletions(-) diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index c42b9bb..0c34e5d 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -20,4 +20,6 @@ jobs: go mod tidy go get . - name: Build - run: go build -o insta-infra . + run: | + CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -o insta-infra-linux-arm64 . + CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o insta-infra-linux-amd64 . diff --git a/.gitignore b/.gitignore index b0bfcfd..caf9a61 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ .idea __pycache__ data/*/persist +insta-infra* + diff --git a/README.md b/README.md index 3512546..96dae55 100644 --- a/README.md +++ b/README.md @@ -101,6 +101,7 @@ If any data is persisted from the services to carry across sessions, it gets pus ## Install/Build ```shell +docker run -v ~/code/insta-infra/:/tmp/insta-infra -it golang:1.22.4 bash go install data-catering/insta-infra -go build -o insta-infra . +CGO_ENABLED=0 GOOS=darwin GOARCH=arm64 go build -o insta-infra-darwin-arm64 . ``` \ No newline at end of file diff --git a/docker-compose.yaml b/docker-compose.yaml index 01c9752..6643b88 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -1,4 +1,3 @@ -version: "3.9" services: #database cassandra: @@ -7,7 +6,7 @@ services: environment: - "DS_LICENSE=accept" volumes: - - "${HOME}/data/cassandra:/var/lib/cassandra" + - "./data/cassandra/persist:/var/lib/cassandra" - "./data/cassandra/my_data.cql:/docker-entrypoint-initdb.d/my_data.cql" healthcheck: test: [ "CMD-SHELL", "[ $$(nodetool statusgossip) = running ]" ] @@ -30,8 +29,8 @@ services: - "ELASTIC_PASSWORD=elasticsearch" - "discovery.type=single-node" volumes: + - "./data/elasticsearch/persist:/usr/share/elasticsearch/data:Z" - "./data/elasticsearch/config/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml:ro,Z" - - "${HOME}/data/elasticsearch:/usr/share/elasticsearch/data:Z" ports: - "9200:9200" - "9300:9300" @@ -46,7 +45,7 @@ services: - "MARIADB_ROOT_PASSWORD=root" - "MARIADB_DATABASE=customer" volumes: - - "${HOME}/data/mariadb:/var/lib/mysql:Z" + - "./data/mariadb/persist:/var/lib/mysql:Z" - "./data/mariadb:/opt/app" ports: - "3306:3306" @@ -59,7 +58,7 @@ services: - "MONGO_INITDB_ROOT_USERNAME=user" - "MONGO_INITDB_ROOT_PASSWORD=password" volumes: - - "${HOME}/data/mongodb:/data/db" + - "./data/mongodb/persist:/data/db" ports: - "27017:27017" @@ -81,7 +80,7 @@ services: - "MYSQL_ROOT_PASSWORD=root" command: "--mysql-native-password=ON" volumes: - - "${HOME}/data/mysql:/var/lib/mysql" + - "./data/mysql/persist:/var/lib/mysql" - "./data/mysql/my_data.sql:/docker-entrypoint-initdb.d/my_data.sql" healthcheck: test: [ "CMD-SHELL", "mysqladmin" ,"ping", "-h", "localhost", "-u", "root", "-p$$MYSQL_ROOT_PASSWORD" ] @@ -98,7 +97,7 @@ services: - "POSTGRES_PASSWORD=postgres" - "PGDATA=/data/postgres" volumes: - - "${HOME}/data/postgres:/data/postgres" + - "./data/postgres/persist:/data/postgres" - "./data/postgres/my_data.sql:/docker-entrypoint-initdb.d/my_data.sql" healthcheck: test: [ "CMD-SHELL", "pg_isready" ] @@ -122,7 +121,7 @@ services: - "POSTGRES_USER=postgres" - "POSTGRES_PASSWORD=postgres" volumes: - - "${HOME}/data/marquez:/opt/marquez" + - "./data/marquez/persist:/opt/marquez" - "./data/marquez:/opt/app" ports: - "5002:5000" @@ -288,7 +287,7 @@ services: - "DAGSTER_POSTGRES_DB=dagster" - "DAGSTER_HOME=/opt/dagster/dagster_home/" volumes: - - "${HOME}/data/dagster:/opt/dagster/dagster_home/" + - "./data/dagster/persist:/opt/dagster/dagster_home/" - "./data/dagster:/opt/dagster/app/" ports: - "3000:3000" @@ -305,7 +304,7 @@ services: ports: - "6789:6789" volumes: - - "${HOME}/data/mage-ai:/home/src/" + - "./data/mage-ai/persist:/home/src/" restart: "on-failure" prefect-server: @@ -318,7 +317,7 @@ services: - "PREFECT_SERVER_API_HOST=0.0.0.0" - "PREFECT_API_DATABASE_CONNECTION_URL=postgresql+asyncpg://postgres:postgres@postgres:5432/prefect" volumes: - - "${HOME}/data/prefect:/root/.prefect" + - "./data/prefect/persist:/root/.prefect" ports: - "4200:4200" depends_on: @@ -349,7 +348,7 @@ services: - "KAFKA_ADVERTISED_LISTENERS=PLAINTEXT://kafka:29092,PLAINTEXT_HOST://localhost:9092" - "KAFKA_LISTENERS=PLAINTEXT://kafka:29092,CONTROLLER://localhost:29093,PLAINTEXT_HOST://0.0.0.0:9092" volumes: - - "${HOME}/data/kafka:/var/lib/kafka/data" + - "./data/kafka/persist:/var/lib/kafka/data" healthcheck: test: [ "CMD-SHELL", "/bin/sh", "-c", "kafka-topics", "--bootstrap-server", "kafka:29092", "--list" ] interval: "15s" @@ -378,7 +377,7 @@ services: - "username_admin_password=admin" - "system_scaling_maxconnectioncount=100" volumes: - - "${HOME}/data/solace:/var/lib/solace" + - "./data/solace/persist:/var/lib/solace" healthcheck: test: [ "CMD-SHELL", "curl", "--output", "/dev/null", "--silent", "--head", "--fail", "http://localhost:8080" ] interval: "30s" @@ -417,7 +416,7 @@ services: - "MINIO_ROOT_USER=minioadmin" - "MINIO_ROOT_PASSWORD=minioadmin" volumes: - - "${HOME}/data/minio:/data" + - "./data/minio/persist:/data" ports: - "9000:9000" - "9001:9001" diff --git a/go.mod b/go.mod index 628f5c3..8442784 100644 --- a/go.mod +++ b/go.mod @@ -1,15 +1,11 @@ module data-catering/insta-infra -go 1.21 +go 1.22 require ( + github.com/compose-spec/compose-go/v2 v2.1.1 github.com/docker/cli v26.1.4+incompatible github.com/docker/compose/v2 v2.27.1 - github.com/docker/docker v26.1.4+incompatible // indirect -) - -require ( - github.com/compose-spec/compose-go/v2 v2.1.1 github.com/urfave/cli/v2 v2.27.2 ) @@ -51,6 +47,7 @@ require ( github.com/distribution/reference v0.6.0 // indirect github.com/docker/buildx v0.14.1 // indirect github.com/docker/distribution v2.8.3+incompatible // indirect + github.com/docker/docker v26.1.3+incompatible // indirect github.com/docker/docker-credential-helpers v0.8.0 // indirect github.com/docker/go v1.5.1-1.0.20160303222718-d30aec9fd63c // indirect github.com/docker/go-connections v0.5.0 // indirect diff --git a/go.sum b/go.sum index 98c3bdd..2ee0753 100644 --- a/go.sum +++ b/go.sum @@ -137,8 +137,8 @@ github.com/docker/compose/v2 v2.27.1/go.mod h1:JZVWp9uVnP59S3KoVne6MboJRpx/eNr9H github.com/docker/distribution v2.7.1+incompatible/go.mod h1:J2gT2udsDAN96Uj4KfcMRqY0/ypR+oyYUYmja8H+y+w= github.com/docker/distribution v2.8.3+incompatible h1:AtKxIZ36LoNK51+Z6RpzLpddBirtxJnzDrHLEKxTAYk= github.com/docker/distribution v2.8.3+incompatible/go.mod h1:J2gT2udsDAN96Uj4KfcMRqY0/ypR+oyYUYmja8H+y+w= -github.com/docker/docker v26.1.4+incompatible h1:vuTpXDuoga+Z38m1OZHzl7NKisKWaWlhjQk7IDPSLsU= -github.com/docker/docker v26.1.4+incompatible/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk= +github.com/docker/docker v26.1.3+incompatible h1:lLCzRbrVZrljpVNobJu1J2FHk8V0s4BawoZippkc+xo= +github.com/docker/docker v26.1.3+incompatible/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk= github.com/docker/docker-credential-helpers v0.8.0 h1:YQFtbBQb4VrpoPxhFuzEBPQ9E16qz5SpHLS+uswaCp8= github.com/docker/docker-credential-helpers v0.8.0/go.mod h1:UGFXcuoQ5TxPiB54nHOZ32AWRqQdECoh/Mg0AlEYb40= github.com/docker/go v1.5.1-1.0.20160303222718-d30aec9fd63c h1:lzqkGL9b3znc+ZUgi7FlLnqjQhcXxkNM/quxIjBVMD0= diff --git a/insta.go b/insta.go index 41790f3..06fa7c0 100644 --- a/insta.go +++ b/insta.go @@ -38,7 +38,9 @@ func main() { EnableBashCompletion: true, Commands: []*cli.Command{ { - Usage: "Run services", + Name: "run", + Aliases: []string{"-r"}, + Usage: "Run services", Action: func(cCtx *cli.Context) error { err := runServices(ctx, srv, p, cCtx.Args().Slice()) if err != nil { @@ -47,18 +49,9 @@ func main() { return nil }, }, - { - Name: "run", - Aliases: []string{"r"}, - Usage: "Run services", - Action: func(cCtx *cli.Context) error { - fmt.Println("run task: ", cCtx.Args().First()) - return nil - }, - }, { Name: "connect", - Aliases: []string{"c"}, + Aliases: []string{"-c"}, Usage: "Connect to a service", Action: func(cCtx *cli.Context) error { fmt.Println("connect task: ", cCtx.Args().First()) @@ -67,7 +60,7 @@ func main() { }, { Name: "down", - Aliases: []string{"d"}, + Aliases: []string{"-d"}, Usage: "Bring all services down", Action: func(cCtx *cli.Context) error { err := downServices(ctx, srv, p, cCtx.Args().Slice()) @@ -79,7 +72,7 @@ func main() { }, { Name: "update", - Aliases: []string{"u"}, + Aliases: []string{"-u"}, Usage: "Update to the latest service versions", Action: func(cCtx *cli.Context) error { fmt.Println("update task: ", cCtx.Args().First()) @@ -87,6 +80,7 @@ func main() { }, }, }, + DefaultCommand: "--help", } if err := app.Run(os.Args); err != nil {