Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Docker compose #185

Merged
merged 3 commits into from
Oct 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 28 additions & 9 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,23 @@ on:
branches:
- master
pull_request:

jobs:
lint:
name: Lint and fmt check
runs-on: ubuntu-latest
steps:
- name: Check out source code
uses: actions/checkout@v4

- name: Set up Go
uses: actions/setup-go@v5
with:
go-version-file: "go.mod"

- name: Linting and fmt check
run: make lint

build:
name: CI
runs-on: ubuntu-latest
Expand All @@ -17,16 +33,19 @@ jobs:
with:
go-version-file: './go.mod'

- name: Start dependencies
run: make deps-start

- name: Running CI
run: make ci

- name: Convert coverage file to lcov
run: |
GO111MODULE=off go get -u github.com/jandelgado/gcov2lcov
$(go env GOPATH)/bin/gcov2lcov -infile=coverage.txt -outfile=coverage.lcov

- name: Coveralls
uses: coverallsapp/github-action@master
- name: Codecov
uses: codecov/codecov-action@v4
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
path-to-lcov: ./coverage.lcov
fail_ci_if_error: true # optional (default = false)
files: ./coverage.txt
name: codecov-umbrella # optional
token: ${{ secrets.CODECOV_TOKEN }} # required

- name: Stop dependencies
run: make deps-stop
28 changes: 10 additions & 18 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
VERSION?="0.0.1"
DOCKER = docker

default: test

test: fmtcheck
go test ./... -cover -race

testint: fmtcheck deps
testint: fmtcheck
go test ./... -cover -race -tags=integration -count=1
docker stop harvester-consul
docker stop harvester-redis



cover: fmtcheck
go test ./... -coverpkg=./... -coverprofile=cover.out -tags=integration -covermode=atomic && \
go tool cover -func=cover.out &&\
Expand All @@ -24,27 +20,23 @@ fmtcheck:
@sh -c "'$(CURDIR)/scripts/gofmtcheck.sh'"

lint: fmtcheck
$(DOCKER) run --env=GOFLAGS=-mod=vendor --rm -v $(CURDIR):/app -w /app golangci/golangci-lint:v1.61.0 golangci-lint -v run
docker run --env=GOFLAGS=-mod=vendor --rm -v $(CURDIR):/app -w /app golangci/golangci-lint:v1.61.0 golangci-lint -v run

deeplint: fmtcheck
$(DOCKER) run --env=GOFLAGS=-mod=vendor --rm -v $(CURDIR):/app -w /app golangci/golangci-lint:v1.61.0 golangci-lint run --exclude-use-default=false --enable-all -D dupl --build-tags integration
docker run --env=GOFLAGS=-mod=vendor --rm -v $(CURDIR):/app -w /app golangci/golangci-lint:v1.61.0 golangci-lint run --exclude-use-default=false --enable-all -D dupl --build-tags integration

deps:
docker container inspect harvester-consul > /dev/null 2>&1 || docker run -d --rm -p 8500:8500 -p 8600:8600/udp --name=harvester-consul consul:1.4.3 agent -server -ui -node=server-1 -bootstrap-expect=1 -client=0.0.0.0 -http-port 8500 -log-level=err
docker container inspect harvester-redis > /dev/null 2>&1 || docker run -d --rm -p 6379:6379 --name harvester-redis -e ALLOW_EMPTY_PASSWORD=yes bitnami/redis:6.2
deps-start:
docker compose up -d

deps-stop:
docker stop harvester-consul
docker stop harvester-redis
docker compose down

ci: fmtcheck lint deps
ci: fmtcheck
go test ./... -race -cover -tags=integration -coverprofile=coverage.txt -covermode=atomic
docker stop harvester-consul
docker stop harvester-redis


# disallow any parallelism (-j) for Make. This is necessary since some
# commands during the build process create temporary files that collide
# under parallel conditions.
.NOTPARALLEL:

.PHONY: default test testint cover fmt fmtcheck lint deeplint ci deps deps-stop
.PHONY: default test testint cover fmt fmtcheck lint deeplint ci deps-start deps-stop
30 changes: 18 additions & 12 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,6 @@
version: '2'

networks:
consul-network:
driver: bridge

services:
consul:
container_name: harvester_consul_dev
image: consul:1.15
image: bitnami/consul:latest
networks:
- consul-network
ports:
Expand All @@ -17,9 +10,22 @@ services:
- '8500:8500'
- '8600:8600'
- '8600:8600/udp'

environment:
- CONSUL_BOOTSTRAP_EXPECT=1
- CONSUL_CLIENT_LAN_ADDRESS=0.0.0.0
- CONSUL_DISABLE_KEYRING_FILE=true
- CONSUL_NODE_NAME=server-1
- CONSUL_HTTP_PORT_NUMBER=8500
- CONSUL_ENABLE_UI=true
- CONSUL_AGENT_MODE=server

redis:
container_name: harvester_redis_dev
image: redis:alpine
image: docker.io/bitnami/redis:6.2
environment:
- ALLOW_EMPTY_PASSWORD=yes
ports:
- '6379:6379'
- "6379:6379"

networks:
consul-network:
driver: bridge