Skip to content

Commit

Permalink
Decouple CI and local test commands
Browse files Browse the repository at this point in the history
  • Loading branch information
helder-junior committed Jul 29, 2024
1 parent b602de8 commit 9151888
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 12 deletions.
2 changes: 0 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,11 @@ jobs:
steps:
- name: Check out the repo
uses: actions/checkout@v4
- run: make build-dev
- run: make test-ci
server-tests:
name: Run server tests
runs-on: ubuntu-latest
steps:
- name: Check out the repo
uses: actions/checkout@v4
- run: cd server && make build-dev
- run: cd server && make test-ci
11 changes: 7 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,6 @@ test:
@make deps-start
@docker run -i -v ./:/app --network eventsgateway_eventsgateway eventsgateway-client-dev sh -c 'make test-go'

test-ci:
@docker compose up eventsgateway-api
@docker run -i --network eventsgateway_eventsgateway eventsgateway-client-dev sh -c 'make test-go'

spark-notebook:
@docker compose up jupyter

Expand All @@ -41,6 +37,13 @@ setup:
@go mod tidy
@cd .git/hooks && ln -sf ./hooks/pre-commit.sh pre-commit

# Run all CI commands inside a single Make target to make easier debugging.
test-ci:
@docker build -t eventsgateway-client-dev -f dev.Dockerfile .
@docker build -t eventsgateway-server -f server/Dockerfile server
@docker compose -f docker-compose-ci.yaml up -d eventsgateway-api --wait
@docker run -i --network eventsgateway_eventsgateway eventsgateway-client-dev sh -c 'make test-go'

test-go: unit integration test-coverage-func

unit: print-unit-section unit-run copy-unit-cover
Expand Down
67 changes: 67 additions & 0 deletions docker-compose-ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
services:
zookeeper:
image: confluentinc/cp-zookeeper:6.2.15
ports:
- 2181:2181
environment:
ZOOKEEPER_CLIENT_PORT: 2181
networks:
- eventsgateway

kafka:
image: confluentinc/cp-kafka:6.2.15 #Kafka 2.8
ports:
- 9092:9092
environment:
KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://kafka:9092
KAFKA_LISTENERS: PLAINTEXT://:9092
KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181
KAFKA_CREATE_TOPICS: uploads-au_default:1:0
KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: "1"
KAFKA_TRANSACTION_STATE_LOG_REPLICATION_FACTOR: "1"
depends_on:
zookeeper:
condition: service_started
healthcheck:
test: [ "CMD", "nc", "-z", "localhost", "9092" ]
interval: 5s
timeout: 10s
retries: 10
networks:
- eventsgateway

jaeger:
image: jaegertracing/all-in-one:latest
environment:
- COLLECTOR_OTLP_ENABLED=true
ports:
- "5775:5775/udp"
- "6831:6831/udp"
- "6832:6832/udp"
- "5778:5778"
- "16686:16686"
- "4317:4317"
networks:
- eventsgateway

eventsgateway-api:
image: eventsgateway-server
ports:
- "5000:5000"
- "6060:6060"
depends_on:
kafka:
condition: service_healthy
jaeger:
condition: service_started
healthcheck:
test: [ "CMD", "nc", "-z", "localhost", "5000" ]
interval: 5s
timeout: 10s
retries: 10

networks:
- eventsgateway

networks:
eventsgateway:
2 changes: 1 addition & 1 deletion server/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ ADD .. /go/src/github.com/topfreegames/eventsgateway

RUN apk add --no-cache make git g++ && \
cd /go/src/github.com/topfreegames/eventsgateway && \
make build && \
make build-go && \
mv bin/eventsgateway /app/eventsgateway && \
mv config /app/config

Expand Down
11 changes: 6 additions & 5 deletions server/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ GOBIN="${GOPATH}/bin"
TEST_PACKAGES=`find . -type f -name "*.go" ! \( -path "*vendor*" \) | sed -En "s/([^\.])\/.*/\1/p" | uniq`

run:
@docker compose up eventsgateway-api --wait
@docker compose -f ../docker-compose.yaml up eventsgateway-api --wait

build-dev:
@docker build -t eventsgateway-server-dev -f dev.Dockerfile .
Expand All @@ -24,14 +24,15 @@ deps-stop:
test:
@docker run -i -v ./:/app eventsgateway-server-dev sh -c 'make test-go'

test-ci:
@docker run -i eventsgateway-server-dev sh -c 'make test-go'

test-go:
@${GOBIN}/ginkgo -tags unit -cover -r --randomize-all --randomize-suites ${TEST_PACKAGES}

build-go:
@mkdir -p bin && go build -o ./bin/eventsgateway main.go

build-image:
@docker build -t eventsgateway-server -f Dockerfile .
@docker build -t eventsgateway-server -f Dockerfile .

test-ci:
@docker build -t eventsgateway-server-dev -f dev.Dockerfile .
@docker run -i eventsgateway-server-dev sh -c 'make test-go'

0 comments on commit 9151888

Please sign in to comment.