-
Notifications
You must be signed in to change notification settings - Fork 302
/
buildspec.yml
90 lines (89 loc) · 5.14 KB
/
buildspec.yml
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
version: 0.2
phases:
install:
runtime-versions:
golang: 1.13
pre_build:
commands:
# GOPATH is setup like the following in Codebuild standard 4.0 image
# /go:/codebuild/output/src<some numbers>
# so we copy all the source code to the go root install location before
# invoking any go command.
# this also allows us to build using dep while the transition to go modules is ongoing
- ls -lah
- mkdir -p /go/src/github.com/aws/amazon-ecs-cli
- cp -R . /go/src/github.com/aws/amazon-ecs-cli/
- cd /go/src/github.com/aws/amazon-ecs-cli
# At least one unit test expects no region to be set in the environment. Unset for testing, then reset.
- export AWS_REGION_BAK=$AWS_REGION && export AWS_REGION=
- export AWS_DEFAULT_REGION_BAK=$AWS_DEFAULT_REGION && export AWS_DEFAULT_REGION=
- go test -race -v -cover ./ecs-cli/modules/...
- export AWS_DEFAULT_REGION=$AWS_DEFAULT_REGION_BAK
- export AWS_REGION=$AWS_REGION_BAK
# make a copy of the version.go because `go run gen/version-gen.go` will
# modify it.
- cp ./ecs-cli/modules/version/version.go ./ecs-cli/modules/version/_version.go
# need to cd into the version package because version-gen.go assumes the relative
# location of the VERSION file.
- cd ./ecs-cli/modules/version/
# since we are running the go program inside a Linux container, has to hardcode
# the GOOS and GOARCH correspondinly regardless of what the host OS is.
- GOOS=linux GOARCH=amd64 ECS_RELEASE=cleanbuild go run gen/version-gen.go
build:
commands:
- echo "cd into go root directory"
- cd /go/src/github.com/aws/amazon-ecs-cli
- echo "Compilation context:"
- echo "CODEBUILD_SOURCE_VERSION=$CODEBUILD_SOURCE_VERSION"
- VERSION=`git tag --points-at HEAD`
- echo "VERSION=$VERSION"
- GIT_COMMIT_ID=`git rev-parse HEAD`
- echo "GIT_COMMIT_ID=$GIT_COMMIT_ID"
# TODO: Get rid of the VERSION file after we fully switch to the new CI/CD
- CHECKED_IN_VERSION=`cat /go/src/github.com/aws/amazon-ecs-cli/VERSION`
- echo "VERSION_FILE=$CHECKED_IN_VERSION"
- echo "GOPATH=$GOPATH"
# Check if there is a tag currently pointing at the head and exit if not.
- |
if [ -z "$VERSION" ]; then
echo "the current commit is not tagged. Stopping the build stage..."
exit 1
fi
- |
# $CHECKED_IN_VERSION is not prefixed with "v", only the semantic version number,
# such as 1.17.0 instead of v1.17.0, which is what normal version tags look like.
if [ -n "$VERSION" ] && [ "$VERSION" != "v$CHECKED_IN_VERSION" ]; then
echo "the VERSION file contains a version number that is different from the git tag. file: $CHECKED_IN_VERSION, tag: $VERSION"
exit 1
fi
- GOOS=windows GOARCH=amd64 CGO_ENABLED=0 go build -installsuffix cgo -a -ldflags "-s" -o $CODEBUILD_SRC_DIR/aws/amazon-ecs-cli/ecs-cli-windows-amd64-$VERSION.exe ./ecs-cli/
- GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -installsuffix cgo -a -ldflags "-s" -o $CODEBUILD_SRC_DIR/aws/amazon-ecs-cli/ecs-cli-linux-amd64-$VERSION ./ecs-cli/
- GOOS=linux GOARCH=arm64 CGO_ENABLED=0 go build -installsuffix cgo -a -ldflags "-s" -o $CODEBUILD_SRC_DIR/aws/amazon-ecs-cli/ecs-cli-linux-arm64-$VERSION ./ecs-cli/
- GOOS=darwin GOARCH=amd64 CGO_ENABLED=0 go build -installsuffix cgo -a -ldflags "-s" -o $CODEBUILD_SRC_DIR/aws/amazon-ecs-cli/ecs-cli-darwin-amd64-$VERSION ./ecs-cli/
finally:
- echo "CD into codebuild src directory for last phase"
- cd $CODEBUILD_SRC_DIR
- echo "built artifacts:"
- ls -lah aws/amazon-ecs-cli/
- ./aws/amazon-ecs-cli/ecs-cli-linux-amd64-$VERSION --version
post_build:
commands:
# restore the version file
- mv /go/src/github.com/aws/amazon-ecs-cli/ecs-cli/modules/version/_version.go /go/src/github.com/aws/amazon-ecs-cli/ecs-cli/modules/version/version.go
- echo "Creating latest artifacts..."
- cp aws/amazon-ecs-cli/ecs-cli-windows-amd64-$VERSION.exe aws/amazon-ecs-cli/ecs-cli-windows-amd64-latest.exe
- cp aws/amazon-ecs-cli/ecs-cli-linux-amd64-$VERSION aws/amazon-ecs-cli/ecs-cli-linux-amd64-latest
- cp aws/amazon-ecs-cli/ecs-cli-linux-arm64-$VERSION aws/amazon-ecs-cli/ecs-cli-linux-arm64-latest
- cp aws/amazon-ecs-cli/ecs-cli-darwin-amd64-$VERSION aws/amazon-ecs-cli/ecs-cli-darwin-amd64-latest
- MANIFESTFILE="$GIT_COMMIT_ID.manifest"
- echo "aws/amazon-ecs-cli/ecs-cli-windows-amd64-$VERSION.exe" >> $MANIFESTFILE
- echo "aws/amazon-ecs-cli/ecs-cli-linux-amd64-$VERSION" >> $MANIFESTFILE
- echo "aws/amazon-ecs-cli/ecs-cli-linux-arm64-$VERSION" >> $MANIFESTFILE
- echo "aws/amazon-ecs-cli/ecs-cli-darwin-amd64-$VERSION" >> $MANIFESTFILE
- echo "aws/amazon-ecs-cli/ecs-cli-windows-amd64-latest.exe" >> $MANIFESTFILE
- echo "aws/amazon-ecs-cli/ecs-cli-linux-amd64-latest" >> $MANIFESTFILE
- echo "aws/amazon-ecs-cli/ecs-cli-linux-arm64-latest" >> $MANIFESTFILE
- echo "aws/amazon-ecs-cli/ecs-cli-darwin-amd64-latest" >> $MANIFESTFILE
artifacts:
files:
- '**/*'