Skip to content

Commit d936611

Browse files
committed
Build fix-perms in Makefile
1 parent 6b50ba0 commit d936611

File tree

7 files changed

+43
-41
lines changed

7 files changed

+43
-41
lines changed

.buildkite/docker-compose.yml

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,10 @@ version: '3'
22

33
services:
44
fixperms-tests:
5-
image: golang:latest
5+
image: golang:1.21
66
working_dir: /code
77
environment:
88
CGO_ENABLED: 0
99
volumes:
1010
- ..:/code:ro
1111
command: go test -v ./...
12-
13-
fixperms-build:
14-
image: golang:latest
15-
working_dir: /code
16-
environment:
17-
CGO_ENABLED: 0
18-
volumes:
19-
- ..:/code
20-
- /var/lib/buildkite-agent/git-mirrors:/var/lib/buildkite-agent/git-mirrors
21-
command: .buildkite/steps/build-fixperms.sh

.buildkite/pipeline.yaml

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -22,18 +22,6 @@ steps:
2222
run: fixperms-tests
2323
config: .buildkite/docker-compose.yml
2424

25-
- id: "fixperms-build"
26-
name: ":go: fixperms build"
27-
agents:
28-
queue: "${BUILDKITE_AGENT_META_DATA_QUEUE}"
29-
artifact_paths: "build/fix-perms-*"
30-
plugins:
31-
- docker-compose#v2.1.0:
32-
run: fixperms-build
33-
config: .buildkite/docker-compose.yml
34-
- artifacts#v1.9.0:
35-
upload: "builds/fix-perms-*"
36-
3725
- id: "deploy-service-role-stack"
3826
name: ":aws-iam: :cloudformation:"
3927
agents:
@@ -43,7 +31,6 @@ steps:
4331
- "fmt"
4432
- "lint"
4533
- "fixperms-tests"
46-
- "fixperms-build"
4734

4835
- id: "packer-windows-amd64"
4936
name: ":packer: :windows:"
@@ -56,7 +43,6 @@ steps:
5643
- "fmt"
5744
- "lint"
5845
- "fixperms-tests"
59-
- "fixperms-build"
6046

6147
- id: "launch-windows-amd64"
6248
name: ":cloudformation: :windows: AMD64 Launch"
@@ -101,7 +87,6 @@ steps:
10187
- "fmt"
10288
- "lint"
10389
- "fixperms-tests"
104-
- "fixperms-build"
10590

10691
- id: "launch-linux-amd64"
10792
name: ":cloudformation: :linux: AMD64 Launch"
@@ -145,7 +130,6 @@ steps:
145130
- "fmt"
146131
- "lint"
147132
- "fixperms-tests"
148-
- "fixperms-build"
149133

150134
- id: "launch-linux-arm64"
151135
name: ":cloudformation: :linux: ARM64 Launch"

.buildkite/steps/build-fixperms.sh

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

.buildkite/steps/packer.sh

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,12 @@ fi
1616

1717
mkdir -p "build/"
1818

19-
if [[ "$os" == "linux" ]]; then
20-
buildkite-agent artifact download "build/fix-perms-linux-${arch}" ./build
21-
mv "build/fix-perms-linux-${arch}" packer/linux/conf/buildkite-agent/scripts/fix-buildkite-agent-builds-permissions
22-
chmod 755 packer/linux/conf/buildkite-agent/scripts/fix-buildkite-agent-builds-permissions
23-
fi
24-
2519
# Build a hash of packer files and the agent versions
2620
packer_files_sha=$(find Makefile "packer/${os}" plugins/ -type f -print0 | xargs -0 sha1sum | awk '{print $1}' | sort | sha1sum | awk '{print $1}')
21+
internal_files_sha=$(find go.mod go.sum internal/ -type f -print0 | xargs -0 sha1sum | awk '{print $1}' | sort | sha1sum | awk '{print $1}')
2722
stable_agent_sha=$(curl -Lfs "https://download.buildkite.com/agent/stable/latest/${agent_binary}.sha256")
2823
unstable_agent_sha=$(curl -Lfs "https://download.buildkite.com/agent/unstable/latest/${agent_binary}.sha256")
29-
packer_hash=$(echo "$packer_files_sha" "$arch" "$stable_agent_sha" "$unstable_agent_sha" | sha1sum | awk '{print $1}')
24+
packer_hash=$(echo "$packer_files_sha" "$internal_files_sha" "$arch" "$stable_agent_sha" "$unstable_agent_sha" | sha1sum | awk '{print $1}')
3025

3126
echo "Packer image hash for ${os}/${arch} is ${packer_hash}"
3227
packer_file="packer-${packer_hash}-${os}-${arch}.output"

Makefile

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ PACKER_VERSION ?= 1.9.4
77
PACKER_LINUX_FILES = $(exec find packer/linux)
88
PACKER_WINDOWS_FILES = $(exec find packer/windows)
99

10+
GO_VERSION ?= 1.21
11+
12+
FIXPERMS_FILES = go.mod go.sum $(exec find internal/fixperms)
13+
1014
AWS_REGION ?= us-east-1
1115

1216
ARM64_INSTANCE_TYPE ?= m7g.xlarge
@@ -87,7 +91,7 @@ build/linux-amd64-ami.txt: packer-linux-amd64.output env-AWS_REGION
8791
grep -Eo "$(AWS_REGION): (ami-.+)" $< | cut -d' ' -f2 | xargs echo -n > $@
8892

8993
# Build linux packer image
90-
packer-linux-amd64.output: $(PACKER_LINUX_FILES)
94+
packer-linux-amd64.output: $(PACKER_LINUX_FILES) build/fix-perms-linux-amd64
9195
docker run \
9296
-e AWS_DEFAULT_REGION \
9397
-e AWS_PROFILE \
@@ -120,7 +124,7 @@ print-agent-versions:
120124
@echo Windows: $(CURRENT_AGENT_VERSION_WINDOWS)
121125

122126
# Build linuxarm64 packer image
123-
packer-linux-arm64.output: $(PACKER_LINUX_FILES)
127+
packer-linux-arm64.output: $(PACKER_LINUX_FILES) build/fix-perms-linux-arm64
124128
@echo Agent Version: $(CURRENT_AGENT_VERSION_LINUX)
125129
docker run \
126130
-e AWS_DEFAULT_REGION \
@@ -169,6 +173,31 @@ packer-windows-amd64.output: $(PACKER_WINDOWS_FILES)
169173
-var 'agent_version=$(CURRENT_AGENT_VERSION_WINDOWS)' \
170174
buildkite-ami.pkr.hcl | tee $@
171175

176+
# -----------------------------------------
177+
# fixperms
178+
179+
build/fix-perms-linux-amd64: $(FIXPERMS_FILES)
180+
docker run \
181+
-e CGO_ENABLED=0 \
182+
-e GOOS=linux \
183+
-e GOARCH=amd64 \
184+
-v "$(PWD):/src" \
185+
-w /src \
186+
--rm \
187+
golang:$(GO_VERSION) \
188+
go build -v -buildvcs=false -o "build/fix-perms-linux-amd64" ./internal/fixperms
189+
190+
build/fix-perms-linux-arm64: $(FIXPERMS_FILES)
191+
docker run \
192+
-e CGO_ENABLED=0 \
193+
-e GOOS=linux \
194+
-e GOARCH=arm64 \
195+
-v "$(PWD):/src" \
196+
-w /src \
197+
--rm \
198+
golang:$(GO_VERSION) \
199+
go build -v -buildvcs=false -o "build/fix-perms-linux-arm64" ./internal/fixperms
200+
172201
# -----------------------------------------
173202
# Cloudformation helpers
174203

packer/linux/buildkite-ami.pkr.hcl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,11 @@ build {
8181
source = "../../plugins"
8282
}
8383

84+
provisioner "file" {
85+
destination = "/tmp/build"
86+
source = "../../build"
87+
}
88+
8489
provisioner "shell" {
8590
script = "scripts/install-utils.sh"
8691
}

packer/linux/scripts/install-buildkite-utils.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ echo "Installing bk elastic stack bin files..."
1111
sudo chmod +x /tmp/conf/bin/bk-*
1212
sudo mv /tmp/conf/bin/bk-* /usr/local/bin
1313

14+
echo "Installing fix-buildkite-agent-builds-permissions..."
15+
sudo chmod +x "/tmp/build/fix-perms-linux-${ARCH}"
16+
sudo mv "/tmp/build/fix-perms-linux-${ARCH}" /usr/bin/fix-buildkite-agent-builds-permissions
17+
1418
S3_SECRETS_HELPER_VERSION=2.1.6
1519
echo "Downloading s3-secrets-helper ${S3_SECRETS_HELPER_VERSION}..."
1620
sudo curl -Lsf -o /usr/local/bin/s3secrets-helper \

0 commit comments

Comments
 (0)