2022-11-12 05:12:41pm
This commit is contained in:
parent
b88cd7edb3
commit
3c9e953c41
2 changed files with 112 additions and 6 deletions
|
|
@ -5,7 +5,7 @@ cd -- "$(dirname "$0")/../.."
|
|||
|
||||
help() {
|
||||
cat <<EOF
|
||||
usage: $0 [--rebuild] [--local]
|
||||
usage: $0 [--rebuild] [--local] [--dryrun]
|
||||
|
||||
$0 builds D2 release archives into ./ci/release/build/<version>/d2-<version>.tar.gz
|
||||
|
||||
|
|
@ -17,9 +17,10 @@ Flags:
|
|||
--rebuild: By default build.sh will avoid rebuilding finished assets if they
|
||||
already exist but if you changed something and need to force rebuild, use
|
||||
this flag.
|
||||
--local: By default build.sh uses \$TSTRUCT_MACOS_BUILDER and \$TSTRUCT_LINUX_BUILDER
|
||||
to build the release archives. It's required for now due to the following
|
||||
issue: https://github.com/terrastruct/d2/issues/31
|
||||
--local: By default build.sh uses \$TSTRUCT_MACOS_AMD64_BUILDER,
|
||||
\$TSTRUCT_MACOS_ARM64_BUILDER, \$TSTRUCT_LINUX_AMD64_BUILDER and
|
||||
\$TSTRUCT_LINUX_ARM64_BUILDER to build the release archives. It's required for
|
||||
now due to the following issue: https://github.com/terrastruct/d2/issues/31
|
||||
With --local, build.sh will cross compile locally.
|
||||
warning: This is only for testing purposes, do not use in production!
|
||||
EOF
|
||||
|
|
@ -27,6 +28,12 @@ EOF
|
|||
|
||||
build() {
|
||||
HW_BUILD_DIR="$BUILD_DIR/$OS/$ARCH/d2-$VERSION"
|
||||
ARCHIVE="$BUILD_DIR/d2-$OS-$ARCH-$VERSION.tar.gz"
|
||||
|
||||
if [ -e "$ARCHIVE" -a -z "${REBUILD-}" ]; then
|
||||
log "skipping as already built at $ARCHIVE"
|
||||
return 0
|
||||
fi
|
||||
|
||||
sh_c mkdir -p "$HW_BUILD_DIR"
|
||||
sh_c rsync --recursive --perms --delete \
|
||||
|
|
@ -41,7 +48,7 @@ build() {
|
|||
sh_c go build -ldflags "-X oss.terrastruct.com/d2/lib/version.Version=$VERSION" \
|
||||
-o "$HW_BUILD_DIR/bin/d2" ./cmd/d2
|
||||
|
||||
sh_c tar czf "$BUILD_DIR/d2-$OS-$ARCH-$VERSION.tar.gz" "$HW_BUILD_DIR"
|
||||
sh_c tar czf "$ARCHIVE" "$HW_BUILD_DIR"
|
||||
}
|
||||
|
||||
main() {
|
||||
|
|
@ -54,7 +61,8 @@ main() {
|
|||
HW_BUILD_DIR \
|
||||
REBUILD \
|
||||
LOCAL \
|
||||
DRYRUN
|
||||
DRYRUN \
|
||||
ARCHIVE
|
||||
VERSION="$(git_describe_ref)"
|
||||
BUILD_DIR="ci/release/build/$VERSION"
|
||||
while :; do
|
||||
|
|
|
|||
98
ci/release/builders/init_aws.sh
Executable file
98
ci/release/builders/init_aws.sh
Executable file
|
|
@ -0,0 +1,98 @@
|
|||
#!/bin/sh
|
||||
set -eu
|
||||
cd -- "$(dirname "$0")/../../.."
|
||||
. ./ci/sub/lib.sh
|
||||
|
||||
help() {
|
||||
cat <<EOF
|
||||
usage: $0 [--dryrun]
|
||||
|
||||
$0 sets up an AWS account with the d2 builders.
|
||||
EOF
|
||||
}
|
||||
|
||||
main() {
|
||||
unset DRYRUN
|
||||
while :; do
|
||||
flag_parse "$@"
|
||||
case "$FLAG" in
|
||||
h|help)
|
||||
help
|
||||
return 0
|
||||
;;
|
||||
dryrun)
|
||||
flag_noarg
|
||||
DRYRUN=1
|
||||
shift "$FLAGSHIFT"
|
||||
;;
|
||||
'')
|
||||
shift "$FLAGSHIFT"
|
||||
break
|
||||
;;
|
||||
*)
|
||||
flag_errusage "unrecognized flag $FLAGRAW"
|
||||
;;
|
||||
esac
|
||||
done
|
||||
if [ $# -gt 0 ]; then
|
||||
flag_errusage "no arguments are accepted"
|
||||
fi
|
||||
|
||||
init_aws
|
||||
}
|
||||
|
||||
init_aws() {
|
||||
KEY_NAME=$(aws ec2 describe-key-pairs | jq -r .KeyPairs[0].KeyName)
|
||||
VPC_ID=$(aws ec2 describe-vpcs | jq -r .Vpcs[0].VpcId)
|
||||
|
||||
header security-group
|
||||
SG_ID=$(aws ec2 describe-security-groups --group-names ssh 2>/dev/null \
|
||||
| jq -r .SecurityGroups[0].GroupId)
|
||||
if [ -z "$SG_ID" ]; then
|
||||
SG_ID=$(sh_c aws ec2 create-security-group \
|
||||
--group-name ssh \
|
||||
--description ssh \
|
||||
--vpc-id "$VPC_ID" | jq -r .GroupId)
|
||||
fi
|
||||
|
||||
header security-group-ingress
|
||||
SG_RULES_COUNT=$(aws ec2 describe-security-groups --group-names ssh \
|
||||
| jq -r '.SecurityGroups[0].IpPermissions | length')
|
||||
if [ "$SG_RULES_COUNT" -eq 0 ]; then
|
||||
sh_c aws ec2 authorize-security-group-ingress \
|
||||
--group-id "$SG_ID" \
|
||||
--protocol tcp \
|
||||
--port 22 \
|
||||
--cidr 0.0.0.0/0 >/dev/null
|
||||
fi
|
||||
|
||||
header linux-amd64
|
||||
if ! aws ec2 describe-instances \
|
||||
"--query=Reservations[*].Instances[?State.Name!='terminated']" \
|
||||
| grep -q d2-builder-linux-amd64; then
|
||||
sh_c aws ec2 run-instances \
|
||||
--image-id=ami-0d593311db5abb72b \
|
||||
--count=1 \
|
||||
--instance-type=t2.micro \
|
||||
--security-groups=ssh \
|
||||
"--key-name=$KEY_NAME" \
|
||||
--tag-specifications 'ResourceType=instance,Tags=[{Key=Name,Value=d2-builder-linux-amd64}]' \
|
||||
'ResourceType=volume,Tags=[{Key=Name,Value=d2-builder-linux-amd64}]' >/dev/null
|
||||
fi
|
||||
|
||||
header linux-arm64
|
||||
if ! aws ec2 describe-instances \
|
||||
"--query=Reservations[*].Instances[?State.Name!='terminated']" \
|
||||
| grep -q d2-builder-linux-arm64; then
|
||||
sh_c aws ec2 run-instances \
|
||||
--image-id=ami-0efabcf945ffd8831 \
|
||||
--count=1 \
|
||||
--instance-type=t4g.nano \
|
||||
--security-groups=ssh \
|
||||
"--key-name=$KEY_NAME" \
|
||||
--tag-specifications 'ResourceType=instance,Tags=[{Key=Name,Value=d2-builder-linux-arm64}]' \
|
||||
'ResourceType=volume,Tags=[{Key=Name,Value=d2-builder-linux-arm64}]' >/dev/null
|
||||
fi
|
||||
}
|
||||
|
||||
main "$@"
|
||||
Loading…
Reference in a new issue