Skip to content

Commit

Permalink
chore: improve Make macros to use docker volume to speed up local tests
Browse files Browse the repository at this point in the history
- chore: improve Dockerfile.local to speed up local tests and development
  • Loading branch information
Sonia Melgaço committed Feb 28, 2023
1 parent f46c315 commit a1e9028
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 28 deletions.
1 change: 0 additions & 1 deletion Dockerfile.ci-test
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ ENV LIBRDKAFKA_VERSION 0.11.5
ENV CPLUS_INCLUDE_PATH /usr/local/include
ENV LIBRARY_PATH /usr/local/lib
ENV LD_LIBRARY_PATH /usr/local/lib
ENV KAFKA_DEV_VERSION 3.3.1
ENV GOLANGCI_LINT_VERSION 1.15.0
ENV GINKGO_VERSION 1.4.0

Expand Down
57 changes: 33 additions & 24 deletions Dockerfile.local
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,24 @@ ENV LIBRDKAFKA_VERSION 0.11.5
ENV CPLUS_INCLUDE_PATH /usr/local/include
ENV LIBRARY_PATH /usr/local/lib
ENV LD_LIBRARY_PATH /usr/local/lib
ENV KAFKA_DEV_VERSION 3.3.1
ENV KAFKA_DEV_VERSION 3.3.2
ENV KAFKA_SCRIPTS_VERSION 2.13-${KAFKA_DEV_VERSION}
ENV GOLANGCI_LINT_VERSION 1.15.0
ENV GINKGO_VERSION 1.4.0

RUN apt-get install make git g++ bash python wget pkg-config
RUN apt-get install \
make \
git \
g++ \
bash \
python \
wget \
pkg-config
RUN export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig:$PKG_CONFIG_PATH
RUN wget --no-check-certificate -O /root/librdkafka-${LIBRDKAFKA_VERSION}.tar.gz https://github.com/edenhill/librdkafka/archive/v${LIBRDKAFKA_VERSION}.tar.gz && \
tar -xzf /root/librdkafka-${LIBRDKAFKA_VERSION}.tar.gz -C /root && \
cd /root/librdkafka-${LIBRDKAFKA_VERSION} && \
./configure && make && make install && make clean && ./configure --clean
RUN wget --no-check-certificate -O /root/librdkafka-${LIBRDKAFKA_VERSION}.tar.gz https://github.com/edenhill/librdkafka/archive/v${LIBRDKAFKA_VERSION}.tar.gz \
&& tar -xzf /root/librdkafka-${LIBRDKAFKA_VERSION}.tar.gz -C /root \
&& cd /root/librdkafka-${LIBRDKAFKA_VERSION} \
&& ./configure && make && make install && make clean && ./configure --clean

RUN apt update

Expand All @@ -42,17 +50,26 @@ RUN apt install -y postgresql

# kafka bin to test kafka connection, available at /root/kafka/bin/<script_name>
RUN apt install -y openjdk-8-jdk
RUN wget --no-check-certificate -O /root/kafka_${KAFKA_SCRIPTS_VERSION}.tgz https://dlcdn.apache.org/kafka/${KAFKA_DEV_VERSION}/kafka_${KAFKA_SCRIPTS_VERSION}.tgz && \
tar -xzf /root/kafka_${KAFKA_SCRIPTS_VERSION}.tgz -C /root && \
mv /root/kafka_${KAFKA_SCRIPTS_VERSION} /root/kafka && \
rm /root/kafka_${KAFKA_SCRIPTS_VERSION}.tgz
RUN wget --no-check-certificate -O /root/kafka_${KAFKA_SCRIPTS_VERSION}.tgz https://dlcdn.apache.org/kafka/${KAFKA_DEV_VERSION}/kafka_${KAFKA_SCRIPTS_VERSION}.tgz \
&& tar -xzf /root/kafka_${KAFKA_SCRIPTS_VERSION}.tgz -C /root \
&& mv /root/kafka_${KAFKA_SCRIPTS_VERSION} /root/kafka \
&& rm /root/kafka_${KAFKA_SCRIPTS_VERSION}.tgz

# golangci-lint
RUN wget -O /go/bin/golangci-lint-${GOLANGCI_LINT_VERSION}-linux-amd64.tar.gz https://github.com/golangci/golangci-lint/releases/download/v${GOLANGCI_LINT_VERSION}/golangci-lint-${GOLANGCI_LINT_VERSION}-linux-amd64.tar.gz && \
tar -xzf /go/bin/golangci-lint-${GOLANGCI_LINT_VERSION}-linux-amd64.tar.gz -C /go/bin && \
mv /go/bin/golangci-lint-${GOLANGCI_LINT_VERSION}-linux-amd64/golangci-lint /go/bin/ && \
rm -rf /go/bin/golangci-lint-${GOLANGCI_LINT_VERSION}-linux-amd64 && \
rm /go/bin/golangci-lint-${GOLANGCI_LINT_VERSION}-linux-amd64.tar.gz
RUN wget -O /go/bin/golangci-lint-${GOLANGCI_LINT_VERSION}-linux-amd64.tar.gz https://github.com/golangci/golangci-lint/releases/download/v${GOLANGCI_LINT_VERSION}/golangci-lint-${GOLANGCI_LINT_VERSION}-linux-amd64.tar.gz \
&& tar -xzf /go/bin/golangci-lint-${GOLANGCI_LINT_VERSION}-linux-amd64.tar.gz -C /go/bin \
&& mv /go/bin/golangci-lint-${GOLANGCI_LINT_VERSION}-linux-amd64/golangci-lint /go/bin/ \
&& rm -rf /go/bin/golangci-lint-${GOLANGCI_LINT_VERSION}-linux-amd64 \
&& rm /go/bin/golangci-lint-${GOLANGCI_LINT_VERSION}-linux-amd64.tar.gz

# ginkgo
RUN wget -O /ginkgo-v${GINKGO_VERSION}.tar.gz https://github.com/onsi/ginkgo/archive/refs/tags/v${GINKGO_VERSION}.tar.gz \
&& mkdir -p /go/src/github.com/onsi \
&& tar -xzf /ginkgo-v${GINKGO_VERSION}.tar.gz -C /go/src/github.com/onsi \
&& mv /go/src/github.com/onsi/ginkgo-${GINKGO_VERSION} /go/src/github.com/onsi/ginkgo \
&& cd /go/src/github.com/onsi/ginkgo/ginkgo \
&& go build -o /go/bin/ginkgo . \
&& rm -rf /ginkgo-v${GINKGO_VERSION}.tar.gz

# vim to ease development
RUN apt install -y vim
Expand All @@ -61,12 +78,4 @@ RUN go get -u github.com/golang/dep/cmd/dep

WORKDIR /go/src/github.com/topfreegames/pusher

# for development, it is recommended to create a volume here
# ex.: `docker run -i -t -v $PWD:/go/src/github.com/topfreegames/pusher pusher:local bash`
# if you do so, remember to run
ADD . /go/src/github.com/topfreegames/pusher

RUN dep ensure

# build ginkgo cli to run tests
RUN go build -o /go/bin/ginkgo github.com/topfreegames/pusher/vendor/github.com/onsi/ginkgo/ginkgo/
CMD bash
12 changes: 9 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -146,13 +146,19 @@ build-image-dev:
@docker build -f Dockerfile.local -t pusher:local .

lint-container-dev: build-image-dev
@docker run -t -i pusher:local golangci-lint run
@docker run \
--volume "${PWD}":/go/src/github.com/topfreegames/pusher \
pusher:local golangci-lint run

build-container-dev: build-image-dev
@docker run -t -i pusher:local make build
@docker run \
--volume "${PWD}":/go/src/github.com/topfreegames/pusher \
pusher:local bash -c 'dep ensure && make build'

unit-test-container-dev: build-image-dev
@docker run -t -i pusher:local make unit
@docker run \
--volume "${PWD}":/go/src/github.com/topfreegames/pusher \
pusher:local bash -c 'dep ensure && make unit'

start-deps-container-dev:
@echo "Starting dependencies..."
Expand Down

0 comments on commit a1e9028

Please sign in to comment.