Skip to content

Commit d26693a

Browse files
authored
Remove docker-compose in favor of docker (#10)
* Remove docker-compose in favor of docker * Enhance make targets * Remove modd
1 parent cb1337f commit d26693a

File tree

12 files changed

+66
-76
lines changed

12 files changed

+66
-76
lines changed

.devcontainer/devcontainer.json

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22
// https://github.com/microsoft/vscode-dev-containers
33
{
44
"name": "Go",
5-
"context": "..",
6-
"dockerFile": "../Dockerfile",
5+
"image": "golang:1.14",
76
"runArgs": [
87
"--cap-add=SYS_PTRACE",
98
"--security-opt",
@@ -21,7 +20,7 @@
2120
// Use 'forwardPorts' to make a list of ports inside the container available locally.
2221
// "forwardPorts": [],
2322
// Use 'postCreateCommand' to run commands after the container is created.
24-
"postCreateCommand": "apt-get update && apt-get install -y git"
23+
"postCreateCommand": "apt-get update && apt-get install -y git && make install"
2524
// Uncomment to connect as a non-root user. See https://aka.ms/vscode-remote/containers/non-root.
2625
// "remoteUser": "vscode"
27-
}
26+
}

.github/workflows/build.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
name: build
22
on: push
33
jobs:
4-
docker-compose:
4+
ci-build:
55
runs-on: ubuntu-latest
66
steps:
77
- uses: actions/checkout@v2
88
- name: Build
9-
run: docker-compose up --abort-on-container-exit
9+
run: make docker run="make all"

.vscode/extensions.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
"recommendations": [
33
"ms-vscode.go"
44
]
5-
}
5+
}

.vscode/launch.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@
1414
"args": []
1515
}
1616
]
17-
}
17+
}

.vscode/settings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@
66
"go.lintFlags": [
77
"--fast"
88
]
9-
}
9+
}

.vscode/tasks.json

Lines changed: 7 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -4,40 +4,16 @@
44
"version": "2.0.0",
55
"tasks": [
66
{
7-
"label": "all",
7+
"label": "dev",
88
"type": "shell",
9-
"command": "make all",
9+
"command": "make dev",
1010
"problemMatcher": [
1111
"$go"
1212
],
13-
"group": "build"
14-
},
15-
{
16-
"label": "build",
17-
"type": "shell",
18-
"command": "make build",
19-
"problemMatcher": [
20-
"$go"
21-
],
22-
"group": "build"
23-
},
24-
{
25-
"label": "lint",
26-
"type": "shell",
27-
"command": "make lint",
28-
"problemMatcher": [
29-
"$go"
30-
],
31-
"group": "build"
32-
},
33-
{
34-
"label": "test",
35-
"type": "shell",
36-
"command": "make test",
37-
"problemMatcher": [
38-
"$go"
39-
],
40-
"group": "build"
13+
"group": {
14+
"kind": "build",
15+
"isDefault": true
16+
}
4117
}
4218
]
43-
}
19+
}

Dockerfile

Lines changed: 0 additions & 4 deletions
This file was deleted.

Makefile

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,56 @@
11
.DEFAULT_GOAL := help
22

33
.PHONY: all
4-
all: ## full build: build, lint, test
5-
all: build lint test
4+
all: ## full build
5+
all: clean install build fmt lint test
6+
7+
.PHONY: dev
8+
dev: ## fast build
9+
dev: install build fmt lint-fast test
10+
11+
.PHONY: clean
12+
clean: ## go clean
13+
$(call print-target)
14+
go clean -r -i -cache -testcache -modcache
15+
16+
.PHONY: install
17+
install: ## install build tools
18+
$(call print-target)
19+
./install.sh
620

721
.PHONY: build
822
build: ## go build
923
$(call print-target)
1024
go build ./...
1125

26+
.PHONY: fmt
27+
fmt: ## goimports
28+
$(call print-target)
29+
goimports -l -w .
30+
1231
.PHONY: lint
1332
lint: ## golangci-lint
1433
$(call print-target)
1534
golangci-lint run
1635

36+
.PHONY: lint-fast
37+
lint-fast: ## golangci-lint --fast
38+
$(call print-target)
39+
golangci-lint run --fast
40+
1741
.PHONY: test
1842
test: ## go test with race detector and code covarage
1943
$(call print-target)
2044
go test -race -covermode=atomic
2145

46+
.PHONY: docker
47+
docker: ## run in golang container, example: make docker run="make all"
48+
docker run --rm -v $(CURDIR):/app golang:1.14 sh -c "cd /app && $(run)"
49+
2250
.PHONY: help
2351
help:
2452
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
2553

2654
define print-target
27-
@echo "Executing target: \033[36m$@\033[0m"
55+
@printf "Executing target: \033[36m$@\033[0m\n"
2856
endef

README.md

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,9 @@ This is a GitHub repository template for Go. It has been created for ease-of-use
1313
It includes:
1414

1515
- [Visual Studio Code](https://code.visualstudio.com) configuration with [Go](https://code.visualstudio.com/docs/languages/go) and [Remote Container](https://code.visualstudio.com/docs/remote/containers) support,
16-
- [modd](https://github.com/cortesi/modd) configuration,
1716
- dependency management using [Go Modules](https://github.com/golang/go/wiki/Modules),
1817
- linting with [GolangCI-Lint](https://github.com/golangci/golangci-lint),
19-
- build automation via [Make](https://www.gnu.org/software/make), [Docker](https://docs.docker.com/engine), [Docker Compose](https://docs.docker.com/compose), [GitHub Actions](https://github.com/features/actions).
18+
- build automation via [Make](https://www.gnu.org/software/make), [Docker](https://docs.docker.com/engine), [GitHub Actions](https://github.com/features/actions).
2019

2120
`Star` this repository if you find it valuable and worth maintaining.
2221

@@ -32,47 +31,42 @@ It includes:
3231

3332
1. Install [Go](https://golang.org/doc/install) and [Go extension](https://code.visualstudio.com/docs/languages/go).
3433
1. Visual Studio Code: `View``Command Pallete... (F1)` → Select `Go: Install/Update Tools`.
35-
1. See [Dockerfile](Dockerfile) for GolangCI-Lint installation command.
3634

3735
**Make on Windows:** Use [WSL (Windows Subsystem for Linux)](https://docs.microsoft.com/en-us/windows/wsl/install-win10) or try [Make Windows port](https://gist.github.com/evanwill/0207876c3243bbb6863e65ec5dc3f058).
3836

3937
#### Visual Studio Code - Development Container
4038

4139
1. [Setup Development inside a Container](https://code.visualstudio.com/docs/remote/containers#_getting-started).
4240
1. Visual Studio Code inside Container: `View``Command Pallete... (F1)` → Select `Go: Install/Update Tools`.
43-
1. See [Dockerfile](Dockerfile) for GolangCI-Lint installation command.
4441

4542
#### Visual Studio Code - SSH
4643

4744
1. [Setup Remote Development using SSH](https://code.visualstudio.com/docs/remote/ssh#_getting-started).
4845
1. On remote machine: install [Go](https://golang.org/doc/install) and [Go extension](https://code.visualstudio.com/docs/languages/go).
4946
1. Visual Studio Code: `View``Command Pallete... (F1)` → Select `Go: Install/Update Tools`.
50-
1. See [Dockerfile](Dockerfile) for GolangCI-Lint installation command.
5147

5248
### Build
5349

54-
- Terminal: `make all`.
55-
- Visual Studio Code: `Terminal``Run Build Task... (CTRL+ALT+B)` → Select `All`.
56-
- Terminal: `docker-compose up --abort-on-container-exit`. This command is executed by CI build (GitHub Action workflow).
57-
- [modd](https://github.com/cortesi/modd) would execute build on any *.go file change.
50+
- Terminal: `make` to get help for make target.
51+
- Terminal: `make all` to execute a full build.
52+
- Visual Studio Code: `Terminal``Run Build Task... (CTRL+ALT+B)` to execute a fast build.
5853

5954
### Maintainance
6055

6156
1. `Watch` this repository to get notified about new releases, issues, etc.
62-
1. Update Go and GolangCI-Lint version in [Dockerfile](Dockerfile).
57+
1. Update Go version in [Makefile](Makefile) and [devcontainer.json](.devcontainer/devcontainer.json).
58+
1. Update and add additional build tools in [install.sh](install.sh).
6359
1. Configure linters via [.golangci.yml](.golangci.yml).
64-
1. Develop Make targets in [Makefile](Makefile) and assosiated tasks in [.vscode/tasks.json](.vscode/tasks.json).
60+
1. Develop Make targets in [Makefile](Makefile).
6561

6662
Notable files:
6763

6864
- [devcontainer.json](.devcontainer/devcontainer.json) - Visual Studio Code Remote Container configuration
6965
- [.github](.github/workflows/build.yml) - GitHub Action workflow (CI build)
7066
- [.vscode](.vscode) - Visual Studio Code configuration files
7167
- [.golangci.yml](.golangci.yml) - GolangCI-Lint configuration
72-
- [docker-compose.yml](docker-compose.yml) - Compose file used in [CI build](.github/workflows/build.yml)
73-
- [Dockerfile](Dockerfile) - Builder image used in [docker-compose.yml](docker-compose.yml) and [devcontainer.json](.devcontainer/devcontainer.json)
74-
- [Makefile](Makefile) - Make targets used in [docker-compose.yml](docker-compose.yml) and [.vscode/tasks.json](.vscode/tasks.json)
75-
- [modd.conf](modd.conf) - [modd](https://github.com/cortesi/modd) configuration file
68+
- [install.sh](install.sh) - build tools installation script
69+
- [Makefile](Makefile) - Make targets used in [CI build](.github/workflows/build.yml) and [.vscode/tasks.json](.vscode/tasks.json)
7670

7771
## FAQ
7872

@@ -83,7 +77,7 @@ The maintainer does not use GoLand. Fell free to create a pull request for [#2](
8377
### Why GitHub Actions, not any other CI server
8478

8579
GitHub Actions is out-of-the-box if you are already using GitHub.
86-
However, changing to any other CI server should be very simple, because this repository uses Docker Compose to run CI build to make the transition easy.
80+
However, changing to any other CI server should be very simple, because this repository uses Docker to run CI build to make the transition easy.
8781

8882
For [CircleCI](https://circleci.com/docs/2.0/executor-types/#using-machine) create `.circleci/config.yml` file:
8983

@@ -95,7 +89,7 @@ jobs:
9589
image: ubuntu-1604:201903-01
9690
steps:
9791
- checkout
98-
- run: docker-compose up --abort-on-container-exit
92+
- run: make docker run="make all"
9993
```
10094
10195
## Contributing

docker-compose.yml

Lines changed: 0 additions & 9 deletions
This file was deleted.

0 commit comments

Comments
 (0)