Skip to content

Commit

Permalink
Reorganize repository, move to circleCI (#17)
Browse files Browse the repository at this point in the history
* chore: remove semaphore2.0

* chore: reorganize repository.

* chore: add circleci

* Install Golang for integration tests

Signed-off-by: Damien DUPORTAL <[email protected]>

* Use same integrartion_test target on CI as dev machines

Signed-off-by: Damien DUPORTAL <[email protected]>

wip ci

Signed-off-by: Damien DUPORTAL <[email protected]>

wip ci

Signed-off-by: Damien DUPORTAL <[email protected]>

wip ci

Signed-off-by: Damien DUPORTAL <[email protected]>

wip ci

Signed-off-by: Damien DUPORTAL <[email protected]>

wip ci

Signed-off-by: Damien DUPORTAL <[email protected]>

* Cleanup leftover of ci_intergation_test target

Signed-off-by: Damien DUPORTAL <[email protected]>

* use vendor dir on integration tests

* update README, add circleCI badge

* do not use future for comment
  • Loading branch information
jlevesy authored Mar 20, 2019
1 parent 9e86aa8 commit 2dc8be0
Show file tree
Hide file tree
Showing 26 changed files with 267 additions and 229 deletions.
79 changes: 75 additions & 4 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,82 @@
---
version: 2
jobs:
build:
cache:
working_directory: ~/sind
docker:
- image: circleci/golang:1.12.1
environment:
GO111MODULE= "on"
GO111MODULE: "on"
steps:
- checkout
- run: make download
- run: make vendor
- save_cache:
key: sind-{{ .Environment.CIRCLE_SHA1 }}
paths:
- ~/sind

integration_test:
machine:
enabled: true
working_directory: ~/sind
steps:
- run:
name: Install and Setup Go
command: |
curl -sSfL https://dl.google.com/go/go1.12.1.linux-amd64.tar.gz -o go.tgz
echo "2a3fdabf665496a0db5f41ec6af7a9b15a49fbe71a85a50ca38b1f13a103aeec *go.tgz" | sha256sum -c -
mkdir -p "${HOME}/local"
tar --overwrite -C "${HOME}"/local -xzf go.tgz
rm go.tgz
echo 'export GOPATH="${HOME}"/go' >> "${BASH_ENV}"
echo 'export PATH="${GOPATH}"/bin:"${HOME}"/local/go/bin:$PATH' >> "${BASH_ENV}"
source "${BASH_ENV}"
mkdir -p "$GOPATH/src" "$GOPATH/bin" && chmod -R 777 "$GOPATH"
- restore_cache:
keys:
- sind-{{ .Environment.CIRCLE_SHA1 }}
- run:
name: Move repository under GOPATH
command: |
source "${BASH_ENV}"
mkdir -p "${GOPATH}/src/github.com/jlevesy"
mv ~/sind "${GOPATH}/src/github.com/jlevesy"
- run:
name: Run Integration Tests
command: |
source "${BASH_ENV}"
cd "${GOPATH}/src/github.com/jlevesy/sind"
make integration_test
working_directory: /go/src/github.com/{{ORG_NAME}}/{{REPO_NAME}}
unit_test:
docker:
- image: circleci/golang:1.12.1
working_directory: /go/src/github.com/jlevesy/sind
steps:
- run: echo "Success"
- restore_cache:
keys:
- sind-{{ .Environment.CIRCLE_SHA1 }}
- run: mv ~/sind /go/src/github.com/jlevesy
- run:
name: "Install golangci-lint"
command: |
curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh -s v1.15.0
sudo mv ./bin/golangci-lint $GOPATH/bin
rm -rf ./bin
golangci-lint --version
- run: make lint
- run: make unit_test
- run: make binary

workflows:
version: 2
build_and_test:
jobs:
- cache
- unit_test:
requires:
- cache
- integration_test:
requires:
- cache
3 changes: 0 additions & 3 deletions .dockerignore

This file was deleted.

1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
dist/
.gocache/
vendor/
47 changes: 0 additions & 47 deletions .semaphore/semaphore.yml

This file was deleted.

14 changes: 0 additions & 14 deletions Dockerfile.toolbox

This file was deleted.

63 changes: 21 additions & 42 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
DIST_DIR ?= dist

COMPOSE_FILE ?= $(CURDIR)/integration/docker-compose.yaml
export COMPOSE_FILE

.PHONY: all
all: clean build test

Expand All @@ -23,18 +20,16 @@ dry_release: clean
#

.PHONY: test
test: unit_test integration_test

.phony: integration_test
integration_test:
docker-compose \
build \
--build-arg UID=$(shell id -u) \
--build-arg GID=$(shell id -g)
docker-compose \
up --exit-code-from client client
docker-compose \
down -v --remove-orphans
test: lint unit_test integration_test

.PHONY: integration_test
integration_test: clean_docker
go test \
-count=1 \
-v \
-timeout=5m \
-run=$(T) \
./pkg/test

.PHONY: unit_test
unit_test:
Expand All @@ -43,19 +38,27 @@ unit_test:
-cover \
-timeout=5s \
-run=$(T) \
$(shell go list $(CURDIR)/... | grep -v integration)
$(shell go list ./... | grep -v pkg/test)

.PHONY: lint
lint:
golangci-lint run

.PHONY: clean_docker
clean_docker:
-docker rm -f $(shell docker ps -a -q)

#
# Build targets
#

.PHONY: download
download:
go mod download

.PHONY: vendor
vendor:
go mod download
go mod vendor

.PHONY: install
install:
Expand All @@ -66,35 +69,11 @@ build: clean dist binary

.PHONY: binary
binary:
CGO_ENABLED=0 go build -ldflags="-s -w" -o $(DIST_DIR)/sind $(CURDIR)/cmd/sind
CGO_ENABLED=0 go build -ldflags="-s -w" -o $(DIST_DIR)/sind ./cmd/sind

dist:
mkdir -p $(DIST_DIR)

.PHONY: clean
clean:
rm -rf $(DIST_DIR)

#
# Toolbox setup
#

.PHONY: toolbox
toolbox: cachedirs
docker build \
--build-arg=UID=$(shell id -u) \
--build-arg=GID=$(shell id -g) \
-t go-sind-toolbox \
-f Dockerfile.toolbox .

.PHONY: cachedirs
cachedirs: .gocache/mod .gocache/build

.PHONY: clean-cachedirs
rm -rf $(CURDIR)/.gocache

.gocache/mod:
@mkdir -p $(CURDIR)/.gocache/mod

.gocache/build:
@mkdir -p $(CURDIR)/.gocache/build
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# sind

[![CircleCI](https://circleci.com/gh/jlevesy/sind.svg?style=svg)](https://circleci.com/gh/jlevesy/sind)

`sind` enables you to create swarm clusters on a docker host using SIND (swarm in docker).

## Requirements
Expand All @@ -9,17 +11,17 @@

## Using it as a go package

Head to the [base example](./example/base/main.go) or to the [integration test suite](./integration/sind_test.go) to get started.
Head to the [example](./cmd/example/main.go) or to the [integration test suite](./pkg/test) to get started.

## Using it as a CLI

### Installation

- Download the latest release for your platform from <https://github.com/jlevesy/go-sind/releases>
- Download the latest release for your platform from <https://github.com/jlevesy/sind/releases>
- Untar the downloaded archive and move the binary somewhere on your PATH

```shell
curl -sSL -o sind.tar.gz "https://github.com/jlevesy/go-sind/releases/download/v0.1.1/sind_0.1.1_$(uname -s)_$(uname -m).tar.gz"
curl -sSL -o sind.tar.gz "https://github.com/jlevesy/go-sind/releases/download/v0.2.1/sind_0.2.1_$(uname -s)_$(uname -m).tar.gz"

tar xzf ./sind.tar.gz
chmod a+x ./sind
Expand Down Expand Up @@ -47,6 +49,6 @@ unset DOCKER_HOST
sind delete
```

## Why
## Why ?

Mostly for automated testing.
2 changes: 1 addition & 1 deletion example/base/main.go → cmd/example/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"syscall"
"time"

"github.com/jlevesy/go-sind/sind"
"github.com/jlevesy/sind/pkg/sind"
)

func main() {
Expand Down
2 changes: 1 addition & 1 deletion cmd/sind/main.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package main

import "github.com/jlevesy/go-sind/cli"
import "github.com/jlevesy/sind/pkg/cli"

func main() {
cli.Execute()
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module github.com/jlevesy/go-sind
module github.com/jlevesy/sind

require (
github.com/Azure/go-ansiterm v0.0.0-20170929234023-d6e3b3328b78 // indirect
Expand Down
26 changes: 0 additions & 26 deletions integration/docker-compose.yaml

This file was deleted.

10 changes: 5 additions & 5 deletions cli/create.go → pkg/cli/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import (
"fmt"
"os"

"github.com/jlevesy/sind/pkg/sind"
"github.com/jlevesy/sind/pkg/store"
"github.com/spf13/cobra"

"github.com/jlevesy/go-sind/sind"
)

var (
Expand Down Expand Up @@ -40,13 +40,13 @@ func runCreate(cmd *cobra.Command, args []string) {
ctx, cancel := context.WithTimeout(context.Background(), timeout)
defer cancel()

store, err := NewStore()
st, err := store.New()
if err != nil {
fmt.Printf("unable to create store: %v\n", err)
os.Exit(1)
}

if err := store.ValidateName(clusterName); err != nil {
if err := st.Exists(clusterName); err != nil {
fmt.Printf("invalid cluster name: %v\n", err)
os.Exit(1)
}
Expand All @@ -66,7 +66,7 @@ func runCreate(cmd *cobra.Command, args []string) {
os.Exit(1)
}

if err = store.Save(*cluster); err != nil {
if err = st.Save(*cluster); err != nil {
fmt.Printf("unable to save cluster: %v\n", err)
os.Exit(1)
}
Expand Down
Loading

0 comments on commit 2dc8be0

Please sign in to comment.