Skip to content

Commit

Permalink
Merge pull request #772 from buildkite/go-secrets-plugin
Browse files Browse the repository at this point in the history
Integrate Go s3secrets-helper into elastic-stack
  • Loading branch information
pda authored Nov 23, 2020
2 parents 374bcc5 + 19eb25d commit e71d923
Show file tree
Hide file tree
Showing 8 changed files with 65 additions and 3 deletions.
40 changes: 40 additions & 0 deletions .buildkite/pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,44 @@ steps:
run: unit-tests
config: docker-compose.unit-tests.yml

- id: "s3secrets-helper-linux-amd64"
name: ":golang: :linux: s3secrets-helper-linux-amd64"
agents:
queue: "${BUILDKITE_AGENT_META_DATA_QUEUE}"
plugins:
docker#v3.7.0:
image: "golang:1.15"
mount-checkout: false
volumes:
- "./build:/build:rw"
- "./plugins/secrets/s3secrets-helper:/s3secrets-helper:ro"
workdir: /s3secrets-helper
environment:
- "GOOS=linux"
- "GOARCH=amd64"
command: ["go", "build", "-o", "/build/s3secrets-helper-linux-amd64"]
artifact_paths:
- build/s3secrets-helper-linux-amd64

- id: "s3secrets-helper-windows-amd64"
name: ":golang: :windows: s3secrets-helper-windows-amd64.exe"
agents:
queue: "${BUILDKITE_AGENT_META_DATA_QUEUE}"
plugins:
docker#v3.7.0:
image: "golang:1.15"
mount-checkout: false
volumes:
- "./build:/build:rw"
- "./plugins/secrets/s3secrets-helper:/s3secrets-helper:ro"
workdir: /s3secrets-helper
environment:
- "GOOS=windows"
- "GOARCH=amd64"
command: ["go", "build", "-o", "/build/s3secrets-helper-windows-amd64.exe"]
artifact_paths:
- build/s3secrets-helper-windows-amd64.exe

- id: "packer-windows"
name: ":packer: :windows:"
command: .buildkite/steps/packer.sh windows
Expand All @@ -26,6 +64,7 @@ steps:
depends_on:
- "lint"
- "bats-tests"
- "s3secrets-helper-windows-amd64"

- id: "windows-launch"
name: ":cloudformation: :windows: Launch"
Expand Down Expand Up @@ -54,6 +93,7 @@ steps:
depends_on:
- "lint"
- "bats-tests"
- "s3secrets-helper-linux-amd64"

- id: "linux-launch"
name: ":cloudformation: :linux: Launch"
Expand Down
4 changes: 4 additions & 0 deletions .buildkite/steps/packer.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,17 @@ fi

os="${1:-linux}"
agent_binary="buildkite-agent-${os}-amd64"
s3secrets_binary="s3secrets-helper-${os}-amd64"

if [[ "$os" == "windows" ]] ; then
agent_binary+=".exe"
s3secrets_binary+=".exe"
fi

mkdir -p "build/"

buildkite-agent artifact download "build/$s3secrets_binary" .

# Build a hash of packer files and the agent versions
packer_files_sha=$(find Makefile "packer/${os}" plugins/ -type f -print0 | xargs -0 sha1sum | awk '{print $1}' | sort | sha1sum | awk '{print $1}')
stable_agent_sha=$(curl -Lfs "https://download.buildkite.com/agent/stable/latest/${agent_binary}.sha256")
Expand Down
10 changes: 8 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ build/linux-ami.txt: packer-linux.output env-AWS_REGION
grep -Eo "$(AWS_REGION): (ami-.+)" $< | cut -d' ' -f2 | xargs echo -n > $@

# Build linux packer image
packer-linux.output: $(PACKER_LINUX_FILES)
packer-linux.output: $(PACKER_LINUX_FILES) build/s3secrets-helper-linux-amd64
docker run \
-e AWS_DEFAULT_REGION \
-e AWS_PROFILE \
Expand All @@ -87,7 +87,7 @@ build/windows-ami.txt: packer-windows.output env-AWS_REGION
grep -Eo "$(AWS_REGION): (ami-.+)" $< | cut -d' ' -f2 | xargs echo -n > $@

# Build windows packer image
packer-windows.output: $(PACKER_WINDOWS_FILES)
packer-windows.output: $(PACKER_WINDOWS_FILES) build/s3secrets-helper-windows-amd64.exe
docker run \
-e AWS_DEFAULT_REGION \
-e AWS_PROFILE \
Expand Down Expand Up @@ -149,3 +149,9 @@ validate: build/aws-stack.yml
generate-toc:
docker run -it --rm -v "$(PWD):/app" node:slim bash \
-c "npm install -g markdown-toc && cd /app && markdown-toc -i README.md"

build/s3secrets-helper-linux-amd64:
cd plugins/secrets/s3secrets-helper && GOOS=linux GOARCH=amd64 go build -o ../../../$@

build/s3secrets-helper-windows-amd64.exe:
cd plugins/secrets/s3secrets-helper && GOOD=windows GOARCH=amd64 go build -o ../../../$@
5 changes: 5 additions & 0 deletions packer/linux/buildkite-ami.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@
"source": "../../plugins",
"destination": "/tmp/plugins"
},
{
"type": "file",
"source": "../../build/s3secrets-helper-linux-amd64",
"destination": "/tmp/s3secrets-helper"
},
{
"type": "shell",
"script": "scripts/install-utils.sh"
Expand Down
1 change: 1 addition & 0 deletions packer/linux/scripts/install-buildkite-agent.sh
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,4 @@ echo "Copying built-in plugins..."
sudo mkdir -p /usr/local/buildkite-aws-stack/plugins
sudo cp -a /tmp/plugins/* /usr/local/buildkite-aws-stack/plugins/
sudo chown -R buildkite-agent: /usr/local/buildkite-aws-stack
sudo install --mode=0755 /tmp/s3secrets-helper /usr/local/bin
5 changes: 5 additions & 0 deletions packer/windows/buildkite-ami.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@
"source": "../../plugins",
"destination": "C:/packer-temp"
},
{
"type": "file",
"source": "../../build/s3secrets-helper-windows-amd64.exe",
"destination": "C:/packer-temp/s3secrets-helper.exe"
},
{
"type": "powershell",
"script": "scripts/install-utils.ps1"
Expand Down
1 change: 1 addition & 0 deletions packer/windows/scripts/install-buildkite-agent.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,4 @@ Copy-Item -Path C:\packer-temp\conf\buildkite-agent\scripts\stop-agent-gracefull
Write-Output "Copying built-in plugins..."
New-Item -ItemType directory -Path "C:\Program Files\Git\usr\local\buildkite-aws-stack\plugins"
Copy-Item -Recurse -Path C:\packer-temp\plugins\* -Destination "C:\Program Files\Git\usr\local\buildkite-aws-stack\plugins\"
Copy-Item -Path C:\packer-temp\s3secrets-helper.exe -Destination C:\buildkite-agent\bin

0 comments on commit e71d923

Please sign in to comment.