Skip to content

Commit fdc3262

Browse files
committed
make -> mage; bump go version
1 parent 0c387fd commit fdc3262

File tree

17 files changed

+1113
-96
lines changed

17 files changed

+1113
-96
lines changed

.github/workflows/ci.yml

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

.github/workflows/release.yml

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,28 @@ on:
66
- '*'
77

88
jobs:
9+
lint:
10+
runs-on: ubuntu-latest
11+
container:
12+
image: golangci/golangci-lint:v1.20-alpine
13+
options: -w /go/src/github.com/mxssl/dns
14+
steps:
15+
- uses: actions/checkout@v1
16+
- name: Install dependencies
17+
run: ci/install_mage_linux.sh
18+
- name: Lint
19+
run: mage lint
20+
921
docker-release:
1022
runs-on: ubuntu-latest
1123
steps:
1224
- uses: actions/checkout@v1
25+
- name: Install dependencies
26+
run: ci/install_mage_linux.sh
1327
- name: Docker login
1428
run: docker login --username ${{ secrets.DOCKER_LOGIN }} --password ${{ secrets.DOCKER_PASSWORD }}
1529
- name: Docker release
16-
run: make docker-release
30+
run: mage dockerRelease
1731

1832
github-release:
1933
runs-on: ubuntu-latest
@@ -22,11 +36,11 @@ jobs:
2236
- name: Set up Go
2337
uses: actions/setup-go@master
2438
with:
25-
go-version: 1.13.4
39+
go-version: 1.14.2
2640
- name: Run GoReleaser
2741
uses: goreleaser/goreleaser-action@v1
2842
with:
29-
version: v0.123.3
43+
version: v0.131.1
3044
args: release --rm-dist
3145
env:
3246
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.goreleaser.yml

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@ builds:
1010
- windows
1111
goarch:
1212
- amd64
13-
archive:
14-
name_template: "{{ .ProjectName }}_{{ .Os }}_{{ .Arch }}"
15-
files:
16-
- none*
17-
replacements:
18-
darwin: Darwin
19-
linux: Linux
20-
windows: Windows
21-
amd64: x86_64
13+
archives:
14+
- name_template: "{{ .ProjectName }}_{{ .Os }}_{{ .Arch }}"
15+
files:
16+
- none*
17+
replacements:
18+
darwin: Darwin
19+
linux: Linux
20+
windows: Windows
21+
amd64: x86_64
2222
checksum:
2323
name_template: 'checksums.txt'
2424
snapshot:

Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM golang:1.13.4-alpine3.10 as builder
1+
FROM golang:1.14.2-alpine3.11 as builder
22

33
ENV GO111MODULE=on
44

@@ -18,7 +18,7 @@ RUN CGO_ENABLED=0 \
1818
go build -v -mod=vendor -o dns
1919

2020
# Copy compiled binary to clear Alpine Linux image
21-
FROM alpine:3.10.3
21+
FROM alpine:3.11.5
2222
WORKDIR /
2323
RUN apk add --no-cache ca-certificates
2424
COPY --from=builder /go/src/github.com/mxssl/dns/dns /usr/local/bin/dns

Makefile

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

README.md

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,18 @@
88

99
### Download compiled binary
1010

11-
[Linux](https://github.com/mxssl/dns/releases/download/0.0.7/dns_Linux_x86_64.tar.gz)
11+
[Linux](https://github.com/mxssl/dns/releases/download/0.0.8/dns_Linux_x86_64.tar.gz)
1212

13-
[Windows](https://github.com/mxssl/dns/releases/download/0.0.7/dns_Windows_x86_64.tar.gz)
13+
[Windows](https://github.com/mxssl/dns/releases/download/0.0.8/dns_Windows_x86_64.tar.gz)
1414

15-
[MacOS](https://github.com/mxssl/dns/releases/download/0.0.7/dns_Darwin_x86_64.tar.gz)
15+
[MacOS](https://github.com/mxssl/dns/releases/download/0.0.8/dns_Darwin_x86_64.tar.gz)
1616

1717
### Examples
1818

1919
Linux:
2020

2121
```bash
22-
wget https://github.com/mxssl/dns/releases/download/0.0.7/dns_Linux_x86_64.tar.gz
22+
wget https://github.com/mxssl/dns/releases/download/0.0.8/dns_Linux_x86_64.tar.gz
2323
tar zvxf dns_Linux_x86_64.tar.gz
2424
cp dns /usr/local/bin/dns
2525
chmod +x /usr/local/bin/dns
@@ -28,7 +28,7 @@ chmod +x /usr/local/bin/dns
2828
MacOS
2929

3030
```bash
31-
wget https://github.com/mxssl/dns/releases/download/0.0.7/dns_Darwin_x86_64.tar.gz
31+
wget https://github.com/mxssl/dns/releases/download/0.0.8/dns_Darwin_x86_64.tar.gz
3232
tar zvxf dns_Darwin_x86_64.tar.gz
3333
cp dns /usr/local/bin/dns
3434
chmod +x /usr/local/bin/dns
@@ -159,3 +159,20 @@ docker container \
159159
mxssl/dns:0.0.7 \
160160
dns a golang.com
161161
```
162+
163+
## Development
164+
165+
[Mage](https://github.com/magefile/mage) is used as an alternative to `make`.
166+
167+
```sh
168+
mage -l
169+
Targets:
170+
build the app
171+
clean delete compiled binary
172+
dockerBuild build container with latest tag
173+
dockerRelease build and push container to the registry
174+
dockerTestRun test run latest container
175+
gitHubRelease run goreleaser
176+
gitHubReleaseDryRun goreleaser dry run
177+
lint the app
178+
```

ci/install_mage_linux.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/usr/bin/env sh
2+
3+
wget https://github.com/magefile/mage/releases/download/v1.9.0/mage_1.9.0_Linux-64bit.tar.gz
4+
tar zvxf mage_1.9.0_Linux-64bit.tar.gz
5+
cp mage /usr/local/bin/mage
6+
chmod +x /usr/local/bin/mage

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ go 1.12
55
require (
66
github.com/BurntSushi/toml v0.3.1 // indirect
77
github.com/inconshreveable/mousetrap v1.0.0 // indirect
8+
github.com/magefile/mage v1.9.0
89
github.com/mitchellh/go-homedir v1.1.0
910
github.com/spf13/cobra v0.0.3
1011
github.com/spf13/viper v1.3.1

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4=
1212
github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ=
1313
github.com/inconshreveable/mousetrap v1.0.0 h1:Z8tu5sraLXCXIcARxBp/8cbvlwVa7Z1NHg9XEKhtSvM=
1414
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
15+
github.com/magefile/mage v1.9.0 h1:t3AU2wNwehMCW97vuqQLtw6puppWXHO+O2MHo5a50XE=
16+
github.com/magefile/mage v1.9.0/go.mod h1:z5UZb/iS3GoOSn0JgWuiw7dxlurVYTu+/jHXqQg881A=
1517
github.com/magiconair/properties v1.8.0 h1:LLgXmsheXeRoUOBOjtwPQCWIYqM/LU1ayDtDePerRcY=
1618
github.com/magiconair/properties v1.8.0/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ=
1719
github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG+4E0Y=

magefile.go

Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
// +build mage
2+
3+
package main
4+
5+
import (
6+
"fmt"
7+
"os"
8+
9+
"github.com/magefile/mage/sh"
10+
)
11+
12+
// BinaryName ...
13+
var BinaryName = "dns"
14+
15+
// DockerRegistry ...
16+
var DockerRegistry = "mxssl"
17+
18+
// Build the app
19+
func Build() error {
20+
if err := sh.Run("go", "build", "-v", "-mod=vendor", "-o", BinaryName); err != nil {
21+
return err
22+
}
23+
fmt.Printf("%s is successfully built\n", BinaryName)
24+
return nil
25+
}
26+
27+
// Lint the app
28+
func Lint() error {
29+
if err := sh.Run("golangci-lint", "run", "-v"); err != nil {
30+
return err
31+
}
32+
return nil
33+
}
34+
35+
// Clean delete compiled binary
36+
func Clean() error {
37+
if !fileExists(BinaryName) {
38+
return fmt.Errorf("cannnot delete binary: %s doesn't exist", BinaryName)
39+
}
40+
if err := sh.Run("rm", "-f", BinaryName); err != nil {
41+
return err
42+
}
43+
fmt.Printf("%s is successfully deleted\n", BinaryName)
44+
return nil
45+
}
46+
47+
// DockerBuild build container with latest tag
48+
func DockerBuild() error {
49+
containerWithTag := fmt.Sprintf(DockerRegistry + "/" + BinaryName + ":" + "latest")
50+
fmt.Printf("Image: %s\n", containerWithTag)
51+
52+
if err := sh.RunV("docker", "build", "--tag", containerWithTag, "."); err != nil {
53+
return err
54+
}
55+
56+
return nil
57+
}
58+
59+
// DockerTestRun test run latest container
60+
func DockerTestRun() error {
61+
containerWithTag := fmt.Sprintf(DockerRegistry + "/" + BinaryName + ":" + "latest")
62+
fmt.Printf("Image: %s\n", containerWithTag)
63+
64+
if err := sh.RunV("docker", "container", "run", containerWithTag, "dns", "a", "google.com"); err != nil {
65+
return err
66+
}
67+
68+
return nil
69+
}
70+
71+
// DockerRelease build and push container to the registry
72+
func DockerRelease() error {
73+
fmt.Printf("Registry: %s\n", DockerRegistry)
74+
tag, err := getLastGitTag()
75+
if err != nil {
76+
return err
77+
}
78+
fmt.Printf("Git tag: %s\n", tag)
79+
80+
containerWithTag := fmt.Sprintf(DockerRegistry + "/" + BinaryName + ":" + tag)
81+
82+
if err := sh.RunV("docker", "build", "--tag", containerWithTag, "."); err != nil {
83+
return err
84+
}
85+
86+
if err := sh.RunV("docker", "push", containerWithTag); err != nil {
87+
return err
88+
}
89+
90+
return nil
91+
}
92+
93+
// GitHubReleaseDryRun goreleaser dry run
94+
func GitHubReleaseDryRun() error {
95+
tag, err := getLastGitTag()
96+
if err != nil {
97+
return err
98+
}
99+
fmt.Printf("Git tag: %s\n", tag)
100+
101+
_, ok := os.LookupEnv("GITHUB_TOKEN")
102+
if !ok {
103+
fmt.Println("env variable GITHUB_TOKEN is not set\n")
104+
}
105+
106+
if err := sh.RunV("goreleaser", "release", "--rm-dist", "--snapshot", "--skip-publish"); err != nil {
107+
return err
108+
}
109+
return nil
110+
}
111+
112+
// GitHubRelease run goreleaser
113+
func GitHubRelease() error {
114+
tag, err := getLastGitTag()
115+
if err != nil {
116+
return err
117+
}
118+
fmt.Printf("Git tag: %s\n", tag)
119+
120+
_, ok := os.LookupEnv("GITHUB_TOKEN")
121+
if !ok {
122+
fmt.Println("env variable GITHUB_TOKEN is not set\n")
123+
}
124+
125+
if err := sh.RunV("goreleaser", "release", "--rm-dist"); err != nil {
126+
return err
127+
}
128+
return nil
129+
}
130+
131+
// check that file exists
132+
func fileExists(filename string) bool {
133+
info, err := os.Stat(filename)
134+
if os.IsNotExist(err) {
135+
return false
136+
}
137+
return !info.IsDir()
138+
}
139+
140+
// obtain latest git tag
141+
func getLastGitTag() (string, error) {
142+
tag, err := sh.Output("git", "describe", "--abbrev=0", "--tags")
143+
if err != nil {
144+
return "", nil
145+
}
146+
return tag, nil
147+
}

0 commit comments

Comments
 (0)