diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index ea114611..349f3a9e 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -27,7 +27,7 @@ jobs: go-version: '1.21.4' - name: Build - run: go build -v ./cmd/main.go + run: go build -v -o bin/echovault . - name: Test run: make test diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 60c37a55..dbe6e0e1 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -28,3 +28,50 @@ jobs: args: release --clean env: GITHUB_TOKEN: ${{ secrets.GORELEASER_TOKEN }} + + publish_images: + name: Publish docker images to multiple registries + runs-on: ubuntu-latest + permissions: + packages: write + contents: read + attestations: write + id-token: write + steps: + - name: Checkout the repo + uses: actions/checkout@v4 + - name: Login to DockerHub + uses: docker/login-action@f4ef78c080cd8ba55a85445d5b36e214a81df20a + with: + username: ${{ secrets.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_PASSWORD }} + - name: Login to the Container Registry + uses: docker/login-action@65b78e6e13532edd9afa3aa52ac7964289d1a9c1 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + - name: Extract metadata (tags, labels) for Docker + id: meta + uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7 + with: + images: | + my-docker-hub-namespace/my-docker-hub-repository + ghcr.io/${{ github.repository }} + - name: Build and push Docker images + id: push + uses: docker/build-push-action@3b5e8027fcad23fda98b2e3ac259d8d67585f671 + with: + context: . + file: ./Dockerfile.prod + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + - name: Generate artifact attestation + uses: actions/attest-build-provenance@v1 + with: + subject-name: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME}} + subject-digest: ${{ steps.push.outputs.digest }} + push-to-registry: true + + diff --git a/.gitignore b/.gitignore index 90242944..e5fc9402 100644 --- a/.gitignore +++ b/.gitignore @@ -1,9 +1,8 @@ .idea .DS_Store bin -volumes/nodes +internal/volumes/nodes dist/ -pkg/modules/*/aof -pkg/echovault/aof dump.rdb **/*/testdata +echovault/aof diff --git a/.goreleaser.yaml b/.goreleaser.yaml index 66c136c0..0a283b2a 100644 --- a/.goreleaser.yaml +++ b/.goreleaser.yaml @@ -6,7 +6,7 @@ before: - go generate ./... builds: - - main: ./cmd + - main: . env: - CGO_ENABLED=0 goos: diff --git a/Dockerfile.dev b/Dockerfile.dev index 20e0db9d..1181cce9 100644 --- a/Dockerfile.dev +++ b/Dockerfile.dev @@ -1,4 +1,4 @@ -FROM --platform=linux/amd64 golang:alpine as build +FROM --platform=linux/amd64 golang:alpine AS build RUN apk add --no-cache gcc musl-dev @@ -8,28 +8,26 @@ COPY . ./ ENV CGO_ENABLED=1 CC=gcc GOOS=linux GOARCH=amd64 ENV DEST=volumes/modules -RUN CGO_ENABLED=$CGO_ENABLED CC=$CC GOOS=$GOOS GOARCH=$GOARCH go build -buildmode=plugin -o $DEST/module_set/module_set.so ./volumes/modules/module_set/module_set.go -RUN CGO_ENABLED=$CGO_ENABLED CC=$CC GOOS=$GOOS GOARCH=$GOARCH go build -buildmode=plugin -o $DEST/module_get/module_get.so ./volumes/modules/module_get/module_get.go +RUN CGO_ENABLED=$CGO_ENABLED CC=$CC GOOS=$GOOS GOARCH=$GOARCH go build -buildmode=plugin -o $DEST/module_set/module_set.so ./internal/volumes/modules/module_set/module_set.go +RUN CGO_ENABLED=$CGO_ENABLED CC=$CC GOOS=$GOOS GOARCH=$GOARCH go build -buildmode=plugin -o $DEST/module_get/module_get.so ./internal/volumes/modules/module_get/module_get.go -ENV DEST=bin/linux/x86_64 -RUN CGO_ENABLED=$CGO_ENABLED CC=$CC GOOS=$GOOS GOARCH=$GOARCH go build -o $DEST/server ./cmd/main.go +ENV DEST=bin +RUN CGO_ENABLED=$CGO_ENABLED CC=$CC GOOS=$GOOS GOARCH=$GOARCH go build -o $DEST/server . -FROM --platform=linux/amd64 alpine:latest as server +FROM --platform=linux/amd64 alpine:latest AS server -RUN mkdir -p /usr/local/lib/echovault -RUN mkdir -p /opt/echovault/bin -RUN mkdir -p /etc/ssl/certs/echovault/echovault +RUN mkdir -p /usr/echovault/bin/modules +RUN mkdir -p /etc/ssl/certs/echovault/server RUN mkdir -p /etc/ssl/certs/echovault/client -COPY --from=build /build/volumes/modules /opt/echovault/bin/modules -COPY --from=build /build/bin/linux/x86_64/server /opt/echovault/bin - +COPY --from=build /build/volumes/modules /usr/echovault/bin/modules +COPY --from=build /build/bin/server /usr/echovault/bin COPY ./openssl/server /etc/ssl/certs/echovault/server COPY ./openssl/client /etc/ssl/certs/echovault/client -WORKDIR /opt/echovault/bin +WORKDIR /usr/echovault/bin CMD "./server" \ "--bind-addr" "${BIND_ADDR}" \ diff --git a/Dockerfile.prod b/Dockerfile.prod index 04cb3fbc..1a7db699 100644 --- a/Dockerfile.prod +++ b/Dockerfile.prod @@ -1,34 +1,11 @@ -FROM homebrew/brew:latest +FROM --platform=linux/amd64 golang:alpine AS build +RUN apk add --no-cache gcc musl-dev +WORKDIR /build +COPY . ./ +RUN CGO_ENABLED=1 CC=gcc GOOS=linux GOARCH=amd64 go build -o bin/server . -RUN brew tap echovault/echovault -RUN brew install echovault/echovault/echovault - -ENV PORT=7480 -ENV RAFT_PORT=8000 -ENV ML_PORT=7946 -ENV SERVER_ID=1 -ENV PLUGIN_DIR=/usr/local/lib/echovault -ENV DATA_DIR=/var/lib/echovault -ENV TLS=false -ENV MTLS=false -ENV BOOTSTRAP_CLUSTER=false -ENV ACL_CONFIG=/etc/echovault/config/acl.yml -ENV REQUIRE_PASS=false -ENV PASSWORD=password1 -ENV FORWARD_COMMAND=false -ENV SNAPSHOT_THRESHOLD=1000 -ENV SNAPSHOT_INTERVAL=5m30s -ENV RESTORE_SNAPSHOT=true -ENV RESTORE_AOF=false -ENV AOF_SYNC_STRATEGY=everysec -ENV MAX_MEMORY=2000kb -ENV EVICTION_POLICY=noeviction -ENV EVICTION_SAMPLE=20 -ENV EVICTION_INTERVAL=100ms -# List of echovault cert/key pairs -ENV CERT_KEY_PAIR_1=/etc/ssl/certs/echovault/echovault/server1.crt,/etc/ssl/certs/echovault/echovault/server1.key -ENV CERT_KEY_PAIR_2=/etc/ssl/certs/echovault/echovault/server2.crt,/etc/ssl/certs/echovault/echovault/server2.key -# List of client certificate authorities -ENV CLIENT_CA_1=/etc/ssl/certs/echovault/client/rootCA.crt - -ENTRYPOINT ["EchoVault"] +FROM --platform=linux/amd64 alpine:latest AS server +RUN mkdir -p /usr/echovault/bin +COPY --from=build /build/bin/server /usr/echovault/bin +WORKDIR /usr/echovault/bin +ENTRYPOINT ["./server"] \ No newline at end of file diff --git a/Makefile b/Makefile index 12d543ba..54d16636 100644 --- a/Makefile +++ b/Makefile @@ -2,14 +2,14 @@ run: docker-compose up --build build-local: - CGO_ENABLED=1 go build -buildmode=plugin -o ./bin/modules/module_set/module_set.so ./volumes/modules/module_set/module_set.go && \ - CGO_ENABLED=1 go build -buildmode=plugin -o ./bin/modules/module_get/module_get.so ./volumes/modules/module_get/module_get.go && \ - CGO_ENABLED=1 go build -o ./bin ./cmd/... + CGO_ENABLED=1 go build -buildmode=plugin -o ./bin/modules/module_set/module_set.so ./internal/volumes/modules/module_set/module_set.go && \ + CGO_ENABLED=1 go build -buildmode=plugin -o ./bin/modules/module_get/module_get.so ./internal/volumes/modules/module_get/module_get.go && \ + CGO_ENABLED=1 go build -o ./bin ./... build-modules-test: - CGO_ENABLED=1 go build --race=$(RACE) -buildmode=plugin -o $(OUT)/modules/module_set/module_set.so ./volumes/modules/module_set/module_set.go && \ - CGO_ENABLED=1 go build --race=$(RACE) -buildmode=plugin -o $(OUT)/modules/module_get/module_get.so ./volumes/modules/module_get/module_get.go + CGO_ENABLED=1 go build --race=$(RACE) -buildmode=plugin -o $(OUT)/modules/module_set/module_set.so ./internal/volumes/modules/module_set/module_set.go && \ + CGO_ENABLED=1 go build --race=$(RACE) -buildmode=plugin -o $(OUT)/modules/module_get/module_get.so ./internal/volumes/modules/module_get/module_get.go test: env RACE=false OUT=internal/modules/admin/testdata make build-modules-test && \ diff --git a/docker-compose.yaml b/docker-compose.yaml index 713e8ad1..6bf6432e 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -1,5 +1,3 @@ -version: '3.8' - networks: testnet: driver: bridge @@ -34,8 +32,8 @@ services: - EVICTION_SAMPLE=20 - EVICTION_INTERVAL=100ms # List of echovault cert/key pairs - - CERT_KEY_PAIR_1=/etc/ssl/certs/echovault/echovault/server1.crt,/etc/ssl/certs/echovault/echovault/server1.key - - CERT_KEY_PAIR_2=/etc/ssl/certs/echovault/echovault/server2.crt,/etc/ssl/certs/echovault/echovault/server2.key + - CERT_KEY_PAIR_1=/etc/ssl/certs/echovault/server/server1.crt,/etc/ssl/certs/echovault/server/server1.key + - CERT_KEY_PAIR_2=/etc/ssl/certs/echovault/server/server2.crt,/etc/ssl/certs/echovault/server/server2.key # List of client certificate authorities - CLIENT_CA_1=/etc/ssl/certs/echovault/client/rootCA.crt # List of shared object plugins to load on startup @@ -45,8 +43,8 @@ services: - "7480:7480" - "7946:7946" volumes: - - ./volumes/config:/etc/echovault/config - - ./volumes/nodes/standalone_node:/var/lib/echovault + - ./internal/volumes/config:/etc/echovault/config + - ./internal/volumes/nodes/standalone_node:/var/lib/echovault networks: - testnet @@ -78,8 +76,8 @@ services: - EVICTION_SAMPLE=20 - EVICTION_INTERVAL=100ms # List of echovault cert/key pairs - - CERT_KEY_PAIR_1=/etc/ssl/certs/echovault/echovault/server1.crt,/etc/ssl/certs/echovault/echovault/server1.key - - CERT_KEY_PAIR_2=/etc/ssl/certs/echovault/echovault/server2.crt,/etc/ssl/certs/echovault/echovault/server2.key + - CERT_KEY_PAIR_1=/etc/ssl/certs/echovault/server/server1.crt,/etc/ssl/certs/echovault/server/server1.key + - CERT_KEY_PAIR_2=/etc/ssl/certs/echovault/server/server2.crt,/etc/ssl/certs/echovault/server/server2.key # List of client certificate authorities - CLIENT_CA_1=/etc/ssl/certs/echovault/client/rootCA.crt # List of shared object plugins to load on startup @@ -89,8 +87,8 @@ services: - "7481:7480" - "7945:7946" volumes: - - ./volumes/config:/etc/echovault/config - - ./volumes/nodes/cluster_node_1:/var/lib/echovault + - ./internal/volumes/config:/etc/echovault/config + - ./internal/volumes/nodes/cluster_node_1:/var/lib/echovault networks: - testnet @@ -122,8 +120,8 @@ services: - EVICTION_SAMPLE=20 - EVICTION_INTERVAL=100ms # List of echovault cert/key pairs - - CERT_KEY_PAIR_1=/etc/ssl/certs/echovault/echovault/server1.crt,/etc/ssl/certs/echovault/echovault/server1.key - - CERT_KEY_PAIR_2=/etc/ssl/certs/echovault/echovault/server2.crt,/etc/ssl/certs/echovault/echovault/server2.key + - CERT_KEY_PAIR_1=/etc/ssl/certs/echovault/server/server1.crt,/etc/ssl/certs/echovault/server/server1.key + - CERT_KEY_PAIR_2=/etc/ssl/certs/echovault/server/server2.crt,/etc/ssl/certs/echovault/server/server2.key # List of client certificate authorities - CLIENT_CA_1=/etc/ssl/certs/echovault/client/rootCA.crt # List of shared object plugins to load on startup @@ -133,8 +131,8 @@ services: - "7482:7480" - "7947:7946" volumes: - - ./volumes/config:/etc/echovault/config - - ./volumes/nodes/cluster_node_2:/var/lib/echovault + - ./internal/volumes/config:/etc/echovault/config + - ./internal/volumes/nodes/cluster_node_2:/var/lib/echovault networks: - testnet @@ -166,8 +164,8 @@ services: - EVICTION_SAMPLE=20 - EVICTION_INTERVAL=100ms # List of echovault cert/key pairs - - CERT_KEY_PAIR_1=/etc/ssl/certs/echovault/echovault/server1.crt,/etc/ssl/certs/echovault/echovault/server1.key - - CERT_KEY_PAIR_2=/etc/ssl/certs/echovault/echovault/server2.crt,/etc/ssl/certs/echovault/echovault/server2.key + - CERT_KEY_PAIR_1=/etc/ssl/certs/echovault/server/server1.crt,/etc/ssl/certs/echovault/server/server1.key + - CERT_KEY_PAIR_2=/etc/ssl/certs/echovault/server/server2.crt,/etc/ssl/certs/echovault/server/server2.key # List of client certificate authorities - CLIENT_CA_1=/etc/ssl/certs/echovault/client/rootCA.crt # List of shared object plugins to load on startup @@ -177,8 +175,8 @@ services: - "7483:7480" - "7948:7946" volumes: - - ./volumes/config:/etc/echovault/config - - ./volumes/nodes/cluster_node_3:/var/lib/echovault + - ./internal/volumes/config:/etc/echovault/config + - ./internal/volumes/nodes/cluster_node_3:/var/lib/echovault networks: - testnet @@ -210,8 +208,8 @@ services: - EVICTION_SAMPLE=20 - EVICTION_INTERVAL=100ms # List of echovault cert/key pairs - - CERT_KEY_PAIR_1=/etc/ssl/certs/echovault/echovault/server1.crt,/etc/ssl/certs/echovault/echovault/server1.key - - CERT_KEY_PAIR_2=/etc/ssl/certs/echovault/echovault/server2.crt,/etc/ssl/certs/echovault/echovault/server2.key + - CERT_KEY_PAIR_1=/etc/ssl/certs/echovault/server/server1.crt,/etc/ssl/certs/echovault/server/server1.key + - CERT_KEY_PAIR_2=/etc/ssl/certs/echovault/server/server2.crt,/etc/ssl/certs/echovault/server/server2.key # List of client certificate authorities - CLIENT_CA_1=/etc/ssl/certs/echovault/client/rootCA.crt # List of shared object plugins to load on startup @@ -221,8 +219,8 @@ services: - "7484:7480" - "7949:7946" volumes: - - ./volumes/config:/etc/echovault/config - - ./volumes/nodes/cluster_node_4:/var/lib/echovault + - ./internal/volumes/config:/etc/echovault/config + - ./internal/volumes/nodes/cluster_node_4:/var/lib/echovault networks: - testnet @@ -254,8 +252,8 @@ services: - EVICTION_SAMPLE=20 - EVICTION_INTERVAL=100ms # List of echovault cert/key pairs - - CERT_KEY_PAIR_1=/etc/ssl/certs/echovault/echovault/server1.crt,/etc/ssl/certs/echovault/echovault/server1.key - - CERT_KEY_PAIR_2=/etc/ssl/certs/echovault/echovault/server2.crt,/etc/ssl/certs/echovault/echovault/server2.key + - CERT_KEY_PAIR_1=/etc/ssl/certs/echovault/server/server1.crt,/etc/ssl/certs/echovault/server/server1.key + - CERT_KEY_PAIR_2=/etc/ssl/certs/echovault/server/server2.crt,/etc/ssl/certs/echovault/server/server2.key # List of client certificate authorities - CLIENT_CA_1=/etc/ssl/certs/echovault/client/rootCA.crt # List of shared object plugins to load on startup @@ -265,7 +263,7 @@ services: - "7485:7480" - "7950:7946" volumes: - - ./volumes/config:/etc/echovault/config - - ./volumes/nodes/cluster_node_5:/var/lib/echovault + - ./internal/volumes/config:/etc/echovault/config + - ./internal/volumes/nodes/cluster_node_5:/var/lib/echovault networks: - testnet \ No newline at end of file diff --git a/volumes/config/acl.json b/internal/volumes/config/acl.json similarity index 100% rename from volumes/config/acl.json rename to internal/volumes/config/acl.json diff --git a/volumes/config/acl.yml b/internal/volumes/config/acl.yml similarity index 100% rename from volumes/config/acl.yml rename to internal/volumes/config/acl.yml diff --git a/volumes/modules/module_get/module_get.go b/internal/volumes/modules/module_get/module_get.go similarity index 100% rename from volumes/modules/module_get/module_get.go rename to internal/volumes/modules/module_get/module_get.go diff --git a/volumes/modules/module_set/module_set.go b/internal/volumes/modules/module_set/module_set.go similarity index 100% rename from volumes/modules/module_set/module_set.go rename to internal/volumes/modules/module_set/module_set.go diff --git a/cmd/main.go b/main.go similarity index 100% rename from cmd/main.go rename to main.go