Skip to content

Commit

Permalink
Merge pull request #90 from EchoVault/chore/restructure
Browse files Browse the repository at this point in the history
Project Restructuring + Prod Dockerfile
  • Loading branch information
kelvinmwinuka authored Jul 6, 2024
2 parents feb2ffc + 88e23d9 commit a26144c
Show file tree
Hide file tree
Showing 13 changed files with 101 additions and 82 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
47 changes: 47 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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


5 changes: 2 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion .goreleaser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ before:
- go generate ./...

builds:
- main: ./cmd
- main: .
env:
- CGO_ENABLED=0
goos:
Expand Down
24 changes: 11 additions & 13 deletions Dockerfile.dev
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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}" \
Expand Down
43 changes: 10 additions & 33 deletions Dockerfile.prod
Original file line number Diff line number Diff line change
@@ -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"]
10 changes: 5 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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 && \
Expand Down
50 changes: 24 additions & 26 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
version: '3.8'

networks:
testnet:
driver: bridge
Expand Down Expand Up @@ -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
Expand All @@ -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

Expand Down Expand Up @@ -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
Expand All @@ -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

Expand Down Expand Up @@ -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
Expand All @@ -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

Expand Down Expand Up @@ -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
Expand All @@ -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

Expand Down Expand Up @@ -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
Expand All @@ -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

Expand Down Expand Up @@ -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
Expand All @@ -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
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit a26144c

Please sign in to comment.