Skip to content

Commit

Permalink
ci: Simplify dockerfiles, add go vet steps, fix ldflag vals for alpine
Browse files Browse the repository at this point in the history
- Simplify Dockerfiles a bit. Compiling a test binary can be sort of
  useful to fail quickly. But it's better to just run all the tests
  because that happens anyways. Also remove LABEL from all Dockerfiles,
  they aren't used anywhere.
- Add go vet Makefile targets. This tool is built in and provides
  valuable info.
- Make an ldflags value work better on alpine. This was more of an
  annoyance when looking at logs, than anything else. I have manually
  tested this on MacOS and Ubuntu. It works there too.
  • Loading branch information
rafaelespinoza committed Feb 27, 2022
1 parent d4c63a9 commit 6991ba7
Show file tree
Hide file tree
Showing 16 changed files with 52 additions and 33 deletions.
4 changes: 1 addition & 3 deletions .ci/cassandra/client.Dockerfile
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
FROM godfish_test/client_base:latest
LABEL driver=cassandra role=client

WORKDIR /src
RUN go build -v ./drivers/cassandra/godfish && \
go test -c . && go test -c ./drivers/cassandra
RUN make build-cassandra

# Alpine linux doesn't have a cassandra client. Build a golang binary to check
# if server is ready and setup the test DB. Use it in the entrypoint.
Expand Down
3 changes: 3 additions & 0 deletions .ci/cassandra/client.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,6 @@ done

echo "testing godfish against live db"
make test-cassandra ARGS='-v -count=1'

echo "vetting code"
make vet-cassandra
1 change: 0 additions & 1 deletion .ci/cassandra/server_v3.Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
FROM cassandra:3.11.12
LABEL driver=cassandra role=server

# Tests run on a single node, only need to expose the CQL listener port.
EXPOSE 9042
1 change: 0 additions & 1 deletion .ci/cassandra/server_v4.Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
FROM cassandra:4.0.3
LABEL driver=cassandra role=server

# Tests run on a single node, only need to expose the CQL listener port.
EXPOSE 9042
9 changes: 5 additions & 4 deletions .ci/mysql/client.Dockerfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
FROM godfish_test/client_base:latest
LABEL driver=mysql role=client

WORKDIR /src
RUN apk update && apk --no-cache add mysql-client
RUN go build -v ./drivers/mysql/godfish && \
go test -c . && go test -c ./drivers/mysql
RUN apk update && \
apk --no-cache add mysql-client && \
make build-mysql

COPY .ci/mysql/client.sh /
ENTRYPOINT /client.sh
3 changes: 3 additions & 0 deletions .ci/mysql/client.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,6 @@ done

echo "testing godfish against live db"
make test-mysql ARGS='-v -count=1'

echo "vetting code"
make vet-mysql
1 change: 0 additions & 1 deletion .ci/mysql/mariadb_server_v10.Dockerfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
FROM mariadb:10.6
LABEL driver=mysql role=server
EXPOSE 3306
1 change: 0 additions & 1 deletion .ci/mysql/mysql_server_v57.Dockerfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
FROM mysql:5.7
LABEL driver=mysql role=server
EXPOSE 3306
1 change: 0 additions & 1 deletion .ci/mysql/mysql_server_v8.Dockerfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
FROM mysql:8.0
LABEL driver=mysql role=server
EXPOSE 3306
9 changes: 5 additions & 4 deletions .ci/postgres/client.Dockerfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
FROM godfish_test/client_base:latest
LABEL driver=postgres role=client

WORKDIR /src
RUN apk --no-cache add postgresql-client
RUN go build -v ./drivers/postgres/godfish && \
go test -c . && go test -c ./drivers/postgres
RUN apk update && \
apk --no-cache add postgresql-client && \
make build-postgres

COPY .ci/postgres/client.sh /
ENTRYPOINT /client.sh
3 changes: 3 additions & 0 deletions .ci/postgres/client.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,6 @@ done

echo "testing godfish against live db"
make test-postgres ARGS='-v -count=1'

echo "vetting code"
make vet-postgres
1 change: 0 additions & 1 deletion .ci/postgres/server_v12.Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
FROM postgres:12-alpine
LABEL driver=postgres role=server
WORKDIR /var/lib/postgresql
COPY .ci/postgres/server.sh scripts/
RUN scripts/server.sh
Expand Down
1 change: 0 additions & 1 deletion .ci/postgres/server_v13.Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
FROM postgres:13-alpine
LABEL driver=postgres role=server
WORKDIR /var/lib/postgresql
COPY .ci/postgres/server.sh scripts/
RUN scripts/server.sh
Expand Down
7 changes: 2 additions & 5 deletions .ci/sqlite3/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
FROM godfish_test/client_base:latest
LABEL driver=sqlite3
WORKDIR /src

ENV CGO_ENABLED=1
ENV DB_DSN="file:/godfish_test.db"

WORKDIR /src
RUN apk update && \
apk --no-cache add musl-dev sqlite && \
go build -v ./drivers/sqlite3/godfish && \
go test -c . && \
go test -c ./drivers/sqlite3
make build-sqlite3

COPY .ci/sqlite3/client.sh /
ENTRYPOINT /client.sh
3 changes: 3 additions & 0 deletions .ci/sqlite3/client.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,6 @@ make test ARGS='-v -count=1'

echo "testing godfish against live db"
make test-sqlite3 ARGS='-v -count=1'

echo "vetting code"
make vet-sqlite3
37 changes: 27 additions & 10 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,26 @@ GO ?= go
BIN_DIR=bin
PKG_IMPORT_PATH=github.com/rafaelespinoza/godfish

CORE_SRC_PKG_PATHS=$(PKG_IMPORT_PATH) $(PKG_IMPORT_PATH)/internal/...
CASSANDRA_PATH=$(PKG_IMPORT_PATH)/drivers/cassandra
MYSQL_PATH=$(PKG_IMPORT_PATH)/drivers/mysql
POSTGRES_PATH=$(PKG_IMPORT_PATH)/drivers/postgres
SQLITE3_PATH=$(PKG_IMPORT_PATH)/drivers/sqlite3

# inject this metadata when building a binary.
define LDFLAGS
-X $(PKG_IMPORT_PATH)/internal/cmd.versionBranchName=$(shell git rev-parse --abbrev-ref HEAD) \
-X $(PKG_IMPORT_PATH)/internal/cmd.versionBuildTime=$(shell date --rfc-3339=seconds --utc | tr ' ' 'T') \
-X $(PKG_IMPORT_PATH)/internal/cmd.versionBuildTime=$(shell date --utc +%FT%T%z) \
-X $(PKG_IMPORT_PATH)/internal/cmd.versionCommitHash=$(shell git rev-parse --short=7 HEAD) \
-X $(PKG_IMPORT_PATH)/internal/cmd.versionGoVersion=$(shell $(GO) version | awk '{ print $$3 }') \
-X $(PKG_IMPORT_PATH)/internal/cmd.versionTag=$(shell git describe --tag)
endef

test:
$(GO) test $(ARGS) . ./internal/...
$(GO) test $(ARGS) $(CORE_SRC_PKG_PATHS)

vet:
$(GO) vet $(ARGS) $(CORE_SRC_PKG_PATHS)

clean:
rm -rf $(BIN_DIR)
Expand All @@ -25,37 +34,45 @@ build-cassandra: _mkdir
$(GO) build -o $(BIN) -v \
-ldflags "$(LDFLAGS) \
-X $(PKG_IMPORT_PATH)/internal/cmd.versionDriver=cassandra" \
./drivers/cassandra/godfish
$(CASSANDRA_PATH)/godfish
@echo "built cassandra to $(BIN)"
test-cassandra:
$(GO) test $(ARGS) ./drivers/cassandra/...
$(GO) test $(ARGS) $(CASSANDRA_PATH)/...
vet-cassandra: vet
$(GO) vet $(ARGS) $(CASSANDRA_PATH)/...

build-postgres: BIN=$(BIN_DIR)/godfish_postgres
build-postgres: _mkdir
$(GO) build -o $(BIN) -v \
-ldflags "$(LDFLAGS) \
-X $(PKG_IMPORT_PATH)/internal/cmd.versionDriver=postgres" \
./drivers/postgres/godfish
$(POSTGRES_PATH)/godfish
@echo "built postgres to $(BIN)"
test-postgres:
$(GO) test $(ARGS) ./drivers/postgres/...
$(GO) test $(ARGS) $(POSTGRES_PATH)/...
vet-postgres: vet
$(GO) vet $(ARGS) $(POSTGRES_PATH)/...

build-mysql: BIN=$(BIN_DIR)/godfish_mysql
build-mysql: _mkdir
$(GO) build -o $(BIN) -v \
-ldflags "$(LDFLAGS) \
-X $(PKG_IMPORT_PATH)/internal/cmd.versionDriver=mysql" \
./drivers/mysql/godfish
$(MYSQL_PATH)/godfish
@echo "built mysql to $(BIN)"
test-mysql:
$(GO) test $(ARGS) ./drivers/mysql/...
$(GO) test $(ARGS) $(MYSQL_PATH)/...
vet-mysql: vet
$(GO) vet $(ARGS) $(MYSQL_PATH)/...

build-sqlite3: BIN=$(BIN_DIR)/godfish_sqlite3
build-sqlite3: _mkdir
CGO_ENABLED=1 $(GO) build -o $(BIN) -v \
-ldflags "$(LDFLAGS) \
-X $(PKG_IMPORT_PATH)/internal/cmd.versionDriver=sqlite3" \
./drivers/sqlite3/godfish
$(SQLITE3_PATH)/godfish
@echo "built sqlite3 to $(BIN)"
test-sqlite3:
$(GO) test $(ARGS) ./drivers/sqlite3/...
$(GO) test $(ARGS) $(SQLITE3_PATH)/...
vet-sqlite3: vet
$(GO) vet $(ARGS) $(SQLITE3_PATH)/...

0 comments on commit 6991ba7

Please sign in to comment.