Skip to content

Commit

Permalink
fix(test): add healthcheck and cache (#738)
Browse files Browse the repository at this point in the history
  • Loading branch information
zhenghaoz authored Jul 23, 2023
1 parent e5cb249 commit 17f3f73
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 22 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/build_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,8 @@ jobs:
- name: Build the stack
run: docker-compose -f client/docker-compose.yml --project-directory . up -d
env:
DOCKER_BUILDKIT: 1

- name: Check the deployed service URL
uses: jtalk/url-health-check-action@v2
Expand Down
32 changes: 28 additions & 4 deletions client/docker-compose.yml.j2
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ services:
restart: unless-stopped
ports:
- 6379:6379
healthcheck:
test: redis-cli ping
interval: 10s
timeout: 5s
retries: 5

{% if database == 'mysql' %}

Expand All @@ -20,6 +25,11 @@ services:
MYSQL_PASSWORD: gorse_pass
volumes:
- mysql_data:/var/lib/mysql
healthcheck:
test: mysqladmin ping
interval: 10s
timeout: 5s
retries: 5

{% elif database == 'postgres' %}

Expand All @@ -31,6 +41,11 @@ services:
POSTGRES_DB: gorse
POSTGRES_USER: gorse
POSTGRES_PASSWORD: gorse_pass
healthcheck:
test: pg_isready
interval: 10s
timeout: 5s
retries: 5

{% elif database == 'mongo' %}

Expand All @@ -42,6 +57,11 @@ services:
MONGO_INITDB_DATABASE: gorse
MONGO_INITDB_ROOT_USERNAME: root
MONGO_INITDB_ROOT_PASSWORD: password
healthcheck:
test: mongo
interval: 10s
timeout: 5s
retries: 5

{% endif %}

Expand Down Expand Up @@ -107,13 +127,17 @@ services:
- gorse_log:/var/log/gorse
- master_data:/var/lib/gorse
depends_on:
- redis
redis:
condition: service_healthy
{% if database == 'mysql' %}
- mysql
mysql:
condition: service_healthy
{% elif database == 'postgres' %}
- postgres
postgres:
condition: service_healthy
{% elif database == 'mongo' %}
- mongo
mongo:
condition: service_healthy
{% endif %}

volumes:
Expand Down
20 changes: 14 additions & 6 deletions cmd/gorse-master/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,18 +1,26 @@
# syntax = docker/dockerfile:1-experimental

############################
# STEP 1 build executable binary
############################
FROM golang:1.20

COPY . gorse
WORKDIR /src

COPY go.* ./

RUN go mod download

COPY . ./

RUN cd gorse/cmd/gorse-master && \
RUN --mount=type=cache,target=/root/.cache/go-build \
cd cmd/gorse-master && \
CGO_ENABLED=0 go build -ldflags=" \
-X 'github.com/zhenghaoz/gorse/cmd/version.Version=$(git describe --tags $(git rev-parse HEAD))' \
-X 'github.com/zhenghaoz/gorse/cmd/version.GitCommit=$(git rev-parse HEAD)' \
-X 'github.com/zhenghaoz/gorse/cmd/version.BuildTime=$(date)'" . && \
mv gorse-master /usr/bin
-X 'github.com/zhenghaoz/gorse/cmd/version.BuildTime=$(date)'" .

RUN /usr/bin/gorse-master --version
RUN /src/cmd/gorse-master/gorse-master --version

############################
# STEP 2 build a small image
Expand All @@ -21,7 +29,7 @@ FROM scratch

COPY --from=0 /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/

COPY --from=0 /usr/bin/gorse-master /usr/bin/gorse-master
COPY --from=0 /src/cmd/gorse-master/gorse-master /usr/bin/gorse-master

ENV USER root

Expand Down
20 changes: 14 additions & 6 deletions cmd/gorse-server/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,18 +1,26 @@
# syntax = docker/dockerfile:1-experimental

############################
# STEP 1 build executable binary
############################
FROM golang:1.20

COPY . gorse
WORKDIR /src

COPY go.* ./

RUN go mod download

COPY . ./

RUN cd gorse/cmd/gorse-server && \
RUN --mount=type=cache,target=/root/.cache/go-build \
cd cmd/gorse-server && \
CGO_ENABLED=0 go build -ldflags=" \
-X 'github.com/zhenghaoz/gorse/cmd/version.Version=$(git describe --tags $(git rev-parse HEAD))' \
-X 'github.com/zhenghaoz/gorse/cmd/version.GitCommit=$(git rev-parse HEAD)' \
-X 'github.com/zhenghaoz/gorse/cmd/version.BuildTime=$(date)'" . && \
mv gorse-server /usr/bin
-X 'github.com/zhenghaoz/gorse/cmd/version.BuildTime=$(date)'" .

RUN /usr/bin/gorse-server --version
RUN /src/cmd/gorse-server/gorse-server --version

############################
# STEP 2 build a small image
Expand All @@ -21,7 +29,7 @@ FROM scratch

COPY --from=0 /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/

COPY --from=0 /usr/bin/gorse-server /usr/bin/gorse-server
COPY --from=0 /src/cmd/gorse-server/gorse-server /usr/bin/gorse-server

ENV USER root

Expand Down
20 changes: 14 additions & 6 deletions cmd/gorse-worker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,18 +1,26 @@
# syntax = docker/dockerfile:1-experimental

############################
# STEP 1 build executable binary
############################
FROM golang:1.20

COPY . gorse
WORKDIR /src

COPY go.* ./

RUN go mod download

COPY . ./

RUN cd gorse/cmd/gorse-worker && \
RUN --mount=type=cache,target=/root/.cache/go-build \
cd cmd/gorse-worker && \
CGO_ENABLED=0 go build -ldflags=" \
-X 'github.com/zhenghaoz/gorse/cmd/version.Version=$(git describe --tags $(git rev-parse HEAD))' \
-X 'github.com/zhenghaoz/gorse/cmd/version.GitCommit=$(git rev-parse HEAD)' \
-X 'github.com/zhenghaoz/gorse/cmd/version.BuildTime=$(date)'" . && \
mv gorse-worker /usr/bin
-X 'github.com/zhenghaoz/gorse/cmd/version.BuildTime=$(date)'" .

RUN /usr/bin/gorse-worker --version
RUN /src/cmd/gorse-worker/gorse-worker --version

############################
# STEP 2 build a small image
Expand All @@ -21,7 +29,7 @@ FROM scratch

COPY --from=0 /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/

COPY --from=0 /usr/bin/gorse-worker /usr/bin/gorse-worker
COPY --from=0 /src/cmd/gorse-worker/gorse-worker /usr/bin/gorse-worker

ENV USER root

Expand Down

0 comments on commit 17f3f73

Please sign in to comment.