-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile
285 lines (261 loc) · 7.69 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
# SPDX-License-Identifier: Apache-2.0
# Versions installed for OpenSSH and SSHPass binaries.
# This is the ONLY place these hardcoded versions are set.
# They're used in the Dockerfile the GitHub Actions workflow,
# the integration tests, and the static build flags for Go.
# Note: No space between the equals and the value else issues arise.
# renovate: datasource=repology depName=alpine_3_19/openssh versioning=loose
OPENSSH_VERSION=9.7_p1-r4
# renovate: datasource=repology depName=alpine_3_19/sshpass versioning=loose
SSHPASS_VERSION=1.10-r0
# check if a git tag is already set
ifndef GITHUB_TAG
# capture the current git tag we build the application from
GITHUB_TAG = $(shell git describe --tag --abbrev=0)
endif
# create a list of linker flags for building the golang application
LD_FLAGS = \
-X github.com/go-vela/vela-openssh/internal/openssh.OpenSSHVersion=${OPENSSH_VERSION} \
-X github.com/go-vela/vela-openssh/internal/openssh.SSHPassVersion=${SSHPASS_VERSION} \
-X github.com/go-vela/vela-openssh/internal/openssh.PluginVersion=${GITHUB_TAG}
# The `clean` target is intended to clean the workspace
# and prepare the local changes for submission.
#
# Usage: `make clean`
.PHONY: clean
clean: tidy vet fmt fix
# The `run` target is intended to build and
# execute the Docker image for the plugin.
#
# Usage: `make run`
.PHONY: run
run: build docker-build docker-run
# The `tidy` target is intended to clean up
# the Go module files (go.mod & go.sum).
#
# Usage: `make tidy`
.PHONY: tidy
tidy:
@echo
@echo "### Tidying Go module"
@go mod tidy
# The `vet` target is intended to inspect the
# Go source code for potential issues.
#
# Usage: `make vet`
.PHONY: vet
vet:
@echo
@echo "### Vetting Go code"
@go vet ./...
# The `fmt` target is intended to format the
# Go source code to meet the language standards.
#
# Usage: `make fmt`
.PHONY: fmt
fmt:
@echo
@echo "### Formatting Go Code"
@go fmt ./...
# The `fix` target is intended to rewrite the
# Go source code using old APIs.
#
# Usage: `make fix`
.PHONY: fix
fix:
@echo
@echo "### Fixing Go Code"
@go fix ./...
# The `test` target is intended to run
# the tests for the Go source code.
#
# Usage: `make test`
.PHONY: test
test:
@echo
@echo "### Testing Go Code"
@go test ./...
# The `test-cover` target is intended to run
# the tests for the Go source code and then
# open the test coverage report.
#
# Usage: `make test-cover`
.PHONY: test-cover
test-cover:
@echo
@echo "### Creating test coverage report"
@go test -covermode=atomic -coverprofile=coverage.out ./...
@echo
@echo "### Opening test coverage report"
@go tool cover -html=coverage.out
# The `build` target is intended to compile
# the Go source code into a binary.
#
# Usage: `make build`
.PHONY: build
build:
@echo
@echo "### Building release/vela-scp binary"
GOOS=linux CGO_ENABLED=0 \
go build -a \
-ldflags '${LD_FLAGS}' \
-o release/vela-scp \
github.com/go-vela/vela-openssh/cmd/vela-scp
@echo
@echo "### Building release/vela-ssh binary"
GOOS=linux CGO_ENABLED=0 \
go build -a \
-ldflags '${LD_FLAGS}' \
-o release/vela-ssh \
github.com/go-vela/vela-openssh/cmd/vela-ssh
# The `build-static` target is intended to compile
# the Go source code into a statically linked binary.
#
# Usage: `make build-static`
.PHONY: build-static
build-static:
@echo
@echo "### Building static release/vela-scp binary"
GOOS=linux CGO_ENABLED=0 \
go build -a \
-ldflags '-s -w -extldflags "-static" ${LD_FLAGS}' \
-o release/vela-scp \
github.com/go-vela/vela-openssh/cmd/vela-scp
@echo
@echo "### Building static release/vela-ssh binary"
GOOS=linux CGO_ENABLED=0 \
go build -a \
-ldflags '-s -w -extldflags "-static" ${LD_FLAGS}' \
-o release/vela-ssh \
github.com/go-vela/vela-openssh/cmd/vela-ssh
# The `build-static-ci` target is intended to compile
# the Go source code into a statically linked binary
# when used within a CI environment.
#
# Usage: `make build-static-ci`
.PHONY: build-static-ci
build-static-ci:
@echo
@echo "### Building CI static release/vela-scp binary"
@go build -a \
-ldflags '-s -w -extldflags "-static" ${LD_FLAGS}' \
-o release/vela-scp \
github.com/go-vela/vela-openssh/cmd/vela-scp
@echo
@echo "### Building CI static release/vela-ssh binary"
@go build -a \
-ldflags '-s -w -extldflags "-static" ${LD_FLAGS}' \
-o release/vela-ssh \
github.com/go-vela/vela-openssh/cmd/vela-ssh
# The `check` target is intended to output all
# dependencies from the Go module that need updates.
#
# Usage: `make check`
.PHONY: check
check: check-install
@echo
@echo "### Checking dependencies for updates"
@go list -u -m -json all | go-mod-outdated -update
# The `check-direct` target is intended to output direct
# dependencies from the Go module that need updates.
#
# Usage: `make check-direct`
.PHONY: check-direct
check-direct: check-install
@echo
@echo "### Checking direct dependencies for updates"
@go list -u -m -json all | go-mod-outdated -direct
# The `check-full` target is intended to output
# all dependencies from the Go module.
#
# Usage: `make check-full`
.PHONY: check-full
check-full: check-install
@echo
@echo "### Checking all dependencies for updates"
@go list -u -m -json all | go-mod-outdated
# The `check-install` target is intended to download
# the tool used to check dependencies from the Go module.
#
# Usage: `make check-install`
.PHONY: check-install
check-install:
@echo
@echo "### Installing psampaz/go-mod-outdated"
@go get -u github.com/psampaz/go-mod-outdated
# The `bump-deps` target is intended to upgrade
# non-test dependencies for the Go module.
#
# Usage: `make bump-deps`
.PHONY: bump-deps
bump-deps: check
@echo
@echo "### Upgrading dependencies"
@go get -u ./...
# The `bump-deps-full` target is intended to upgrade
# all dependencies for the Go module.
#
# Usage: `make bump-deps-full`
.PHONY: bump-deps-full
bump-deps-full: check
@echo
@echo "### Upgrading all dependencies"
@go get -t -u ./...
# The `docker-build` target is intended to build
# the Docker image for the plugin.
#
# Usage: `make docker-build`
.PHONY: docker-build
docker-build:
@echo
@echo "### Building vela-scp:local image"
@docker build -f Dockerfile.scp --no-cache --build-arg OPENSSH_VERSION=${OPENSSH_VERSION} --build-arg SSHPASS_VERSION=${SSHPASS_VERSION} -t vela-scp:local .
@docker build -f Dockerfile.ssh --no-cache --build-arg OPENSSH_VERSION=${OPENSSH_VERSION} --build-arg SSHPASS_VERSION=${SSHPASS_VERSION} -t vela-ssh:local .
# The `docker-test` target is intended to execute
# the Docker image for the plugin with test variables
# for integration testing the plugins work with other systems.
#
# Usage: `make docker-test`
.PHONY: docker-test
docker-test:
@test/integration-tests.sh
# The `docker-run-scp` target is intended to execute
# the Docker image for the scp plugin.
#
# Usage: `make docker-run-scp`
.PHONY: docker-run-scp
docker-run-scp:
@echo
@echo "### Executing vela-scp:local image"
@docker run --rm \
-e PARAMETER_SOURCE \
-e PARAMETER_TARGET \
-e PARAMETER_IDENTITY_FILE_PATH \
-e PARAMETER_IDENTITY_FILE_CONTENTS \
-e PARAMETER_SCP_FLAG \
-e PARAMETER_SSHPASS_PASSWORD \
-e PARAMETER_SSHPASS_PASSPHRASE \
-e PARAMETER_SSHPASS_FLAG \
-e PARAMETER_CI \
-v $(shell pwd):/home \
vela-scp:local
# The `docker-run-ssh` target is intended to execute
# the Docker image for the ssh plugin.
#
# Usage: `make docker-run-ssh`
.PHONY: docker-run-ssh
docker-run-ssh:
@echo
@echo "### Executing vela-ssh:local image"
@docker run --rm \
-e PARAMETER_DESTINATION \
-e PARAMETER_COMMAND \
-e PARAMETER_IDENTITY_FILE_PATH \
-e PARAMETER_IDENTITY_FILE_CONTENTS \
-e PARAMETER_SSH_FLAG \
-e PARAMETER_SSHPASS_PASSWORD \
-e PARAMETER_SSHPASS_PASSPHRASE \
-e PARAMETER_SSHPASS_FLAG \
-e PARAMETER_CI \
-v $(shell pwd):/home \
vela-scp:local