Skip to content

Commit 29aa709

Browse files
authored
Merge pull request #19 from deckhouse/windows-build
Add Windows support. Build binary for windows-amd64
2 parents 2a7b4fb + fe09df8 commit 29aa709

File tree

5 files changed

+41
-89
lines changed

5 files changed

+41
-89
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Deckhouse Client (d8) is a command-line client for Deckhouse.
44

55
## How to install?
66

7-
### From install script
7+
### From install script (Linux or macOS)
88

99
The install script will automatically grab the latest version of `d8` and install it locally.
1010

Taskfile.yml

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ tasks:
6767
_build:go:dev:
6868
internal: true
6969
cmds:
70-
- go build -o "{{ .outputDir | default (printf "./build/%s-%s" .targetOS .targetArch) }}/d8"
70+
- go build -o "{{ .outputDir | default (printf "./build/%s-%s" .targetOS .targetArch) }}/d8{{ if (eq .targetOS "windows") }}.exe{{ end }}"
7171
-ldflags="{{ .goDevLDFlags }}" -tags="{{ .goTags }}" {{ .CLI_ARGS }} main.go
7272
env:
7373
CGO_ENABLED: "0"
@@ -77,7 +77,7 @@ tasks:
7777
_build:go:dist:
7878
internal: true
7979
cmds:
80-
- go build -o "{{ .outputDir | default (printf "./dist/%s/%s-%s" .version .targetOS .targetArch) }}/d8"
80+
- go build -o "{{ .outputDir | default (printf "./dist/%s/%s-%s" .version .targetOS .targetArch) }}/d8{{ if (eq .targetOS "windows") }}.exe{{ end }}"
8181
-ldflags="{{ .goReleaseLDFlags }}" -tags="{{ .goTags }}" {{ .CLI_ARGS }} main.go
8282
env:
8383
CGO_ENABLED: "0"
@@ -119,12 +119,22 @@ tasks:
119119
targetArch: "arm64"
120120
outputDir: "{{ .outputDir }}"
121121

122+
build:dev:windows:amd64:
123+
desc: Build d8 dev binary for windows/amd64
124+
cmds:
125+
- task: _build:go:dev
126+
vars:
127+
targetOS: "windows"
128+
targetArch: "amd64"
129+
outputDir: "{{.outputDir}}"
130+
122131
build:dist:all:
123132
desc: Build all d8 release binaries in parallel
124133
deps:
125134
- build:dist:linux:amd64
126135
- build:dist:darwin:amd64
127136
- build:dist:darwin:arm64
137+
- build:dist:windows:amd64
128138

129139
build:dist:linux:amd64:
130140
desc: Build d8 release binary for linux/amd64
@@ -153,6 +163,15 @@ tasks:
153163
targetArch: "arm64"
154164
outputDir: "{{ .outputDir }}"
155165

166+
build:dist:windows:amd64:
167+
desc: Build d8 release binary for windows/amd64
168+
cmds:
169+
- task: _build:go:dist
170+
vars:
171+
targetOS: "windows"
172+
targetArch: "amd64"
173+
outputDir: "{{ .outputDir }}"
174+
156175
_package:dist:
157176
dir: dist/{{ .version }}
158177
cmds:
@@ -165,6 +184,7 @@ tasks:
165184
- package:dist:linux:amd64
166185
- package:dist:darwin:amd64
167186
- package:dist:darwin:arm64
187+
- package:dist:windows:amd64
168188

169189
package:dist:linux:amd64:
170190
desc: Package release asset for linux/amd64
@@ -190,6 +210,14 @@ tasks:
190210
vars:
191211
target: "darwin-arm64"
192212

213+
package:dist:windows:amd64:
214+
desc: Package release asset for windows/amd64
215+
dir: dist/{{ .version }}
216+
cmds:
217+
- task: _package:dist
218+
vars:
219+
target: "windows-amd64"
220+
193221
checksum:
194222
desc: Calculate sha256 checksum for release assets
195223
dir: dist/{{ .version }}

internal/mirror/bundle/bundle.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import (
2525
"io/fs"
2626
"os"
2727
"path/filepath"
28+
"strings"
2829

2930
"github.com/deckhouse/deckhouse-cli/internal/mirror/chunked"
3031
"github.com/deckhouse/deckhouse-cli/internal/mirror/contexts"
@@ -131,12 +132,9 @@ func packFunc(mirrorCtx *contexts.BaseContext, out *tar.Writer) filepath.WalkFun
131132
return fmt.Errorf("read file: %w", err)
132133
}
133134

134-
pathInTar, err := filepath.Rel(mirrorCtx.UnpackedImagesPath, path)
135-
if err != nil {
136-
return fmt.Errorf("build file path within bundle: %w", err)
137-
}
135+
pathInTar := strings.TrimPrefix(path, mirrorCtx.UnpackedImagesPath+string(os.PathSeparator))
138136
err = out.WriteHeader(&tar.Header{
139-
Name: pathInTar,
137+
Name: filepath.ToSlash(pathInTar),
140138
Size: info.Size(),
141139
Mode: int64(info.Mode()),
142140
ModTime: info.ModTime(),

internal/mirror/cmd/push/push.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -263,11 +263,11 @@ func pushModulesTags(mirrorCtx *contexts.BaseContext, modulesList []string) erro
263263

264264
func findLayoutsToPush(mirrorCtx *contexts.PushContext) (map[string]layout.Path, []string, error) {
265265
deckhouseIndexRef := mirrorCtx.RegistryHost + mirrorCtx.RegistryPath
266-
installersIndexRef := filepath.Join(deckhouseIndexRef, "install")
267-
releasesIndexRef := filepath.Join(deckhouseIndexRef, "release-channel")
268-
trivyDBIndexRef := filepath.Join(deckhouseIndexRef, "security", "trivy-db")
269-
trivyBDUIndexRef := filepath.Join(deckhouseIndexRef, "security", "trivy-bdu")
270-
trivyJavaDBIndexRef := filepath.Join(deckhouseIndexRef, "security", "trivy-java-db")
266+
installersIndexRef := path.Join(deckhouseIndexRef, "install")
267+
releasesIndexRef := path.Join(deckhouseIndexRef, "release-channel")
268+
trivyDBIndexRef := path.Join(deckhouseIndexRef, "security", "trivy-db")
269+
trivyBDUIndexRef := path.Join(deckhouseIndexRef, "security", "trivy-bdu")
270+
trivyJavaDBIndexRef := path.Join(deckhouseIndexRef, "security", "trivy-java-db")
271271

272272
deckhouseLayoutPath := mirrorCtx.UnpackedImagesPath
273273
installersLayoutPath := filepath.Join(mirrorCtx.UnpackedImagesPath, "install")
@@ -327,8 +327,8 @@ func findLayoutsToPush(mirrorCtx *contexts.PushContext) (map[string]layout.Path,
327327

328328
moduleName := dir.Name()
329329
modulesNames = append(modulesNames, moduleName)
330-
moduleRef := filepath.Join(mirrorCtx.RegistryHost+mirrorCtx.RegistryPath, "modules", moduleName)
331-
moduleReleasesRef := filepath.Join(mirrorCtx.DeckhouseRegistryRepo, "modules", moduleName, "release")
330+
moduleRef := path.Join(mirrorCtx.RegistryHost+mirrorCtx.RegistryPath, "modules", moduleName)
331+
moduleReleasesRef := path.Join(mirrorCtx.DeckhouseRegistryRepo, "modules", moduleName, "release")
332332
moduleLayout, err := layout.FromPath(filepath.Join(modulesPath, moduleName))
333333
if err != nil {
334334
return nil, nil, fmt.Errorf("create module layout from path: %w", err)

internal/mirror/util/tomb/tomb.go

Lines changed: 0 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,7 @@ limitations under the License.
1717
package tomb
1818

1919
import (
20-
"fmt"
21-
"os"
22-
"os/signal"
2320
"sync"
24-
"syscall"
2521

2622
"github.com/deckhouse/deckhouse-cli/internal/mirror/util/log"
2723
)
@@ -91,19 +87,6 @@ func (c *teardownCallbacks) wait() {
9187
<-c.waitCh
9288
}
9389

94-
func RegisterOnShutdown(process string, cb func()) {
95-
callbacks.registerOnShutdown(process, cb)
96-
}
97-
98-
func Shutdown(code int) {
99-
callbacks.shutdown(code)
100-
}
101-
102-
func WaitShutdown() int {
103-
callbacks.wait()
104-
return callbacks.exitCode
105-
}
106-
10790
func IsInterrupted() bool {
10891
select {
10992
case <-callbacks.interruptedCh:
@@ -112,60 +95,3 @@ func IsInterrupted() bool {
11295
}
11396
return false
11497
}
115-
116-
func WithoutInterruptions(fn func()) {
117-
callbacks.notInterruptable = true
118-
defer func() { callbacks.notInterruptable = false }()
119-
fn()
120-
}
121-
122-
func WaitForProcessInterruption() {
123-
interruptCh := make(chan os.Signal, 1)
124-
signal.Notify(interruptCh, syscall.SIGINT, syscall.SIGTERM, syscall.SIGUSR1)
125-
126-
for {
127-
s, ok := <-interruptCh
128-
if !ok {
129-
return
130-
}
131-
132-
var exitCode int
133-
switch s {
134-
case syscall.SIGUSR1:
135-
exitCode = 1
136-
case syscall.SIGTERM, syscall.SIGINT:
137-
exitCode = 0
138-
default:
139-
os.Exit(1)
140-
return
141-
}
142-
143-
if callbacks.notInterruptable {
144-
continue
145-
}
146-
147-
graceShutdownForSignal(interruptCh, exitCode, s)
148-
return
149-
}
150-
}
151-
152-
func graceShutdownForSignal(interruptCh <-chan os.Signal, exitCode int, s os.Signal) {
153-
// Wait for the second signal to kill the main process immediately.
154-
go func() {
155-
<-interruptCh
156-
log.ErrorLn("Killed by signal twice.")
157-
os.Exit(1)
158-
}()
159-
160-
// Close interrupted channel to signal interruptable loops to stop.
161-
close(callbacks.interruptedCh)
162-
163-
// Run all registered teardown callbacks and print an explanation at the end.
164-
callbacks.data = append([]callback{{
165-
Name: "Shutdown message",
166-
Do: func() {
167-
log.WarnLn(fmt.Sprintf("Graceful shutdown by %q signal ...", s.String()))
168-
},
169-
}}, callbacks.data...)
170-
Shutdown(exitCode)
171-
}

0 commit comments

Comments
 (0)