Skip to content
This repository was archived by the owner on Aug 30, 2024. It is now read-only.

Build linux/windows on ubuntu runner #202

Merged
merged 8 commits into from
Dec 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,18 @@ on: [push]

jobs:
build:
runs-on: ubuntu-20.04
steps:
- name: Checkout
uses: actions/checkout@v1
- name: Build
run: make -j build/linux build/windows
- name: Upload
uses: actions/upload-artifact@v2
with:
name: coder-cli
path: ./ci/bin/coder-cli-*
build_darwin:
runs-on: macos-latest
steps:
- name: Checkout
Expand All @@ -17,7 +29,7 @@ jobs:
p12-file-base64: ${{ secrets.APPLE_DEVELOPER_CERTIFICATE_P12_BASE64 }}
p12-password: ${{ secrets.APPLE_DEVELOPER_CERTIFICATE_PASSWORD }}
- name: Build
run: ./ci/steps/build.sh
run: make build/macos
env:
AC_USERNAME: ${{ secrets.AC_USERNAME }}
AC_PASSWORD: ${{ secrets.AC_PASSWORD }}
Expand Down
43 changes: 38 additions & 5 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,25 @@ on:
name: create_github_release
jobs:
build:
name: Create Release
name: Build binaries
runs-on: ubuntu-20.04
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Build
run: make -j build/linux build/windows
- name: Upload linux
uses: actions/upload-artifact@v2
with:
name: coder-cli-linux-amd64
path: ./ci/bin/coder-cli-linux-amd64.tar.gz
- name: Upload windows
uses: actions/upload-artifact@v2
with:
name: coder-cli-windows-386
path: ./ci/bin/coder-cli-windows-386.zip
build_darwin:
name: Build darwin binary
runs-on: macos-latest
steps:
- name: Checkout code
Expand All @@ -19,10 +37,25 @@ jobs:
p12-file-base64: ${{ secrets.APPLE_DEVELOPER_CERTIFICATE_P12_BASE64 }}
p12-password: ${{ secrets.APPLE_DEVELOPER_CERTIFICATE_PASSWORD }}
- name: Build Release Assets
run: ./ci/steps/build.sh
run: make build/macos
env:
AC_USERNAME: ${{ secrets.AC_USERNAME }}
AC_PASSWORD: ${{ secrets.AC_PASSWORD }}
- name: Upload darwin
uses: actions/upload-artifact@v2
with:
name: coder-cli-darwin-amd64
path: ./ci/bin/coder-cli-darwin-amd64.zip
draft_release:
name: Create Release
runs-on: ubuntu-20.04
needs:
- build_darwin
- build
steps:
- uses: actions/download-artifact@v2
- name: content
run: sh -c "ls -al"
- name: Create Release
id: create_release
uses: actions/create-release@v1
Expand All @@ -41,7 +74,7 @@ jobs:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ./ci/bin/coder-cli-linux-amd64.tar.gz
asset_path: coder-cli-linux-amd64/coder-cli-linux-amd64.tar.gz
asset_name: coder-cli-linux-amd64.tar.gz
asset_content_type: application/tar+gzip
- name: Upload MacOS Release
Expand All @@ -51,7 +84,7 @@ jobs:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ./ci/bin/coder-cli-darwin-amd64.zip
asset_path: coder-cli-darwin-amd64/coder-cli-darwin-amd64.zip
asset_name: coder-cli-darwin-amd64.zip
asset_content_type: application/zip
- name: Upload Windows Release
Expand All @@ -61,6 +94,6 @@ jobs:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ./ci/bin/coder-cli-windows-386.zip
asset_path: coder-cli-windows-386/coder-cli-windows-386.zip
asset_name: coder-cli-windows-386.zip
asset_content_type: application/zip
16 changes: 16 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Makefile for Coder CLI

.PHONY: clean build build/macos build/windows build/linux

clean:
rm -rf ./ci/bin

build: build/macos build/windows build/linux

build/macos:
# requires darwin
CGO_ENABLED=1 GOOS=darwin GOARCH=amd64 ./ci/steps/build.sh
build/windows:
CGO_ENABLED=0 GOOS=windows GOARCH=386 ./ci/steps/build.sh
build/linux:
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 ./ci/steps/build.sh
2 changes: 1 addition & 1 deletion ci/integration/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
FROM ubuntu:20.04

RUN apt-get update && apt-get install -y jq curl
RUN apt-get update && apt-get install -y jq curl build-essential
2 changes: 1 addition & 1 deletion ci/integration/setup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func build(path string) error {
cmd := exec.Command(
"sh", "-c",
fmt.Sprintf(
"cd ../../ && mkdir -p %s && ./ci/steps/build.sh && cp ./ci/bin/%s %s/ && tar -xzf %s -C %s",
"cd ../../ && mkdir -p %s && make build/linux && cp ./ci/bin/%s %s/ && tar -xzf %s -C %s",
dir, tar, dir, filepath.Join(dir, tar), dir),
)

Expand Down
84 changes: 35 additions & 49 deletions ci/steps/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,52 +10,38 @@ cd "$(git rev-parse --show-toplevel)/ci/steps"

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be good if we got rid of this script entirely in favour of it being inlined in the makefile

tag=$(git describe --tags)

build() {
echo "--- building coder-cli for $GOOS-$GOARCH"

tmpdir=$(mktemp -d)
go build -ldflags "-X cdr.dev/coder-cli/internal/version.Version=${tag}" -o "$tmpdir/coder" ../../cmd/coder
# For MacOS builds to be notarized.
cp ../gon.json $tmpdir/gon.json

pushd "$tmpdir"
case "$GOOS" in
"windows")
artifact="coder-cli-$GOOS-$GOARCH.zip"
mv coder coder.exe
zip "$artifact" coder.exe
;;
"linux")
artifact="coder-cli-$GOOS-$GOARCH.tar.gz"
tar -czf "$artifact" coder
;;
"darwin")
if [[ ${CI-} ]]; then
artifact="coder-cli-$GOOS-$GOARCH.zip"
gon -log-level debug ./gon.json
mv coder.zip $artifact
else
artifact="coder-cli-$GOOS-$GOARCH.tar.gz"
tar -czf "$artifact" coder
echo "--- warning: not in ci, skipping signed release of darwin"
fi
;;
esac
popd

mkdir -p ../bin
cp "$tmpdir/$artifact" ../bin/$artifact
rm -rf "$tmpdir"
}

# Darwin builds do not work from Linux, so only try to build them from Darwin.
# See: https://github.com/cdr/coder-cli/issues/20
if [[ "$(uname)" == "Darwin" ]]; then
CGO_ENABLED=1 GOOS=darwin GOARCH=amd64 build
else
echo "--- warning: Darwin builds don't work on Linux."
echo "--- please use an OSX machine to build Darwin tars."
fi

CGO_ENABLED=0 GOOS=linux GOARCH=amd64 build
GOOS=windows GOARCH=386 build
echo "--- building coder-cli for $GOOS-$GOARCH"

tmpdir=$(mktemp -d)
go build -ldflags "-X cdr.dev/coder-cli/internal/version.Version=${tag}" -o "$tmpdir/coder" ../../cmd/coder

cp ../gon.json $tmpdir/gon.json

pushd "$tmpdir"
case "$GOOS" in
"windows")
artifact="coder-cli-$GOOS-$GOARCH.zip"
mv coder coder.exe
zip "$artifact" coder.exe
;;
"linux")
artifact="coder-cli-$GOOS-$GOARCH.tar.gz"
tar -czf "$artifact" coder
;;
"darwin")
if [[ ${CI-} ]]; then
artifact="coder-cli-$GOOS-$GOARCH.zip"
gon -log-level debug ./gon.json
mv coder.zip $artifact
else
artifact="coder-cli-$GOOS-$GOARCH.tar.gz"
tar -czf "$artifact" coder
echo "--- warning: not in ci, skipping signed release of darwin"
fi
;;
esac
popd

mkdir -p ../bin
cp "$tmpdir/$artifact" ../bin/$artifact
rm -rf "$tmpdir"
2 changes: 1 addition & 1 deletion pkg/tcli/tcli.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func NewContainerRunner(ctx context.Context, config *ContainerConfig) (*Containe
"run",
"--name", config.Name,
"--network", "host",
"-it", "-d",
"--rm", "-it", "-d",
}
args = append(args, mountArgs(config.BindMounts)...)
args = append(args, config.Image)
Expand Down