Skip to content

Commit

Permalink
Add appveyor.yml for windows builds
Browse files Browse the repository at this point in the history
- Disable 'create-builder' from directories
- Disable tests which require 'create-builder' for directories
- Switch test that assumes "USER" env variables is set to use "PATH"
  (on windows the user env var is "USERNAME", everything has "PATH")

See: https://ci.appveyor.com/project/dgodd/pack

[#29]
  • Loading branch information
dgodd committed Nov 23, 2018
1 parent 22ab1c2 commit eba23ce
Show file tree
Hide file tree
Showing 10 changed files with 122 additions and 32 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,6 @@ artifacts/

# Travis unencrypted file
.travis/key.pem

# Appveyor tools
/appveyor-tools/
Binary file added .travis/key.appveyor.pem.enc
Binary file not shown.
40 changes: 34 additions & 6 deletions acceptance/acceptance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"os/exec"
"path/filepath"
"regexp"
"runtime"
"strings"
"testing"
"time"
Expand Down Expand Up @@ -42,11 +43,14 @@ func TestPack(t *testing.T) {
if err != nil {
panic(err)
}
if txt, err := exec.Command("go", "build", "-o", filepath.Join(packTmpDir, "pack"), "../cmd/pack").CombinedOutput(); err != nil {
pack = filepath.Join(packTmpDir, "pack")
if runtime.GOOS == "windows" {
pack = pack + ".exe"
}
if txt, err := exec.Command("go", "build", "-o", pack, "../cmd/pack").CombinedOutput(); err != nil {
fmt.Println(string(txt))
panic(err)
}
pack = filepath.Join(packTmpDir, "pack")
defer os.RemoveAll(packTmpDir)
}

Expand Down Expand Up @@ -227,6 +231,7 @@ func testPack(t *testing.T, when spec.G, it spec.S) {
})
it.After(func() {
repoName := fmt.Sprintf("pack.local/run/%x", md5.Sum([]byte(sourceCodePath)))
killDockerByRepoName(t, repoName)
dockerCli.ImageRemove(context.TODO(), repoName, dockertypes.ImageRemoveOptions{Force: true, PruneChildren: true})

if sourceCodePath != "" {
Expand All @@ -241,11 +246,9 @@ func testPack(t *testing.T, when spec.G, it spec.S) {
cmd.Stdout = &buf
cmd.Stderr = &buf
cmd.Dir = sourceCodePath
cmd.Start()
h.AssertNil(t, cmd.Start())

defer func() {
h.AssertNil(t, cmd.Process.Signal(os.Interrupt))
}()
defer ctrlCProc(cmd)

h.Eventually(t, func() bool {
return strings.Contains(buf.String(), "Example app listening on port 3000!")
Expand Down Expand Up @@ -376,6 +379,9 @@ func testPack(t *testing.T, when spec.G, it spec.S) {
)

it.Before(func() {
if runtime.GOOS == "windows" {
t.Skip("create builder is not implemented on windows")
}
builderRepoName = "some-org/" + h.RandString(10)
repoName = "some-org/" + h.RandString(10)
containerName = "test-" + h.RandString(10)
Expand Down Expand Up @@ -784,3 +790,25 @@ func waitForPort(t *testing.T, port string, duration time.Duration) {
return err == nil
}, 500*time.Millisecond, duration)
}

func ctrlCProc(cmd *exec.Cmd) error {
if cmd == nil || cmd.Process == nil || cmd.Process.Pid <= 0 {
return fmt.Errorf("invalid pid: %#v", cmd)
}
if runtime.GOOS == "windows" {
return exec.Command("taskkill", "/F", "/T", "/PID", fmt.Sprint(cmd.Process.Pid)).Run()
}
return cmd.Process.Signal(os.Interrupt)
}

func killDockerByRepoName(t *testing.T, repoName string) {
t.Helper()
containers, err := dockerCli.ContainerList(context.Background(), dockertypes.ContainerListOptions{})
h.AssertNil(t, err)

for _, ctr := range containers {
if ctr.Image == repoName {
dockerCli.ContainerRemove(context.Background(), ctr.ID, dockertypes.ContainerRemoveOptions{Force: true})
}
}
}
30 changes: 30 additions & 0 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# appveyor.yml
build: off

stack: go 1.11
cache:
- 'C:\Users\appveyor\go\pkg\mod'

environment:
GO111MODULE: 'on'
APPVEYOR_CACHE_ENTRY_ZIP_ARGS: '-t7z -m0=lzma -mx=9'
PACK_PATH: '%APPVEYOR_BUILD_FOLDER%\artifacts\pack-%APPVEYOR_BUILD_NUMBER%-windows.exe'
DOCKER_CERT_PATH: '%APPVEYOR_BUILD_FOLDER%\.travis'
DOCKER_TLS_VERIFY: '1'
DOCKER_HOST:
secure: mr15I2SOdxk33kgnKOj7MmfH1scjqe4tT2Ptmh7I778=
file_secret:
secure: ZBnL/07wnhfIfOVoGN0vm9EN2tMT5u4JkWVLXBosRrc=

artifacts:
- path: artifacts

before_test:
- go mod download
- go build -ldflags "-X main.Version=gitsha:%APPVEYOR_REPO_COMMIT%" -o %PACK_PATH% ./cmd/pack
- ps: iex ((New-Object Net.WebClient).DownloadString('https://raw.githubusercontent.com/appveyor/secure-file/master/install.ps1'))
- cmd: appveyor-tools\secure-file -decrypt %DOCKER_CERT_PATH%\key.appveyor.pem.enc -out %DOCKER_CERT_PATH%\key.pem -secret %file_secret%

test_script:
- go test -count=1 -parallel=1 -v ./...

4 changes: 4 additions & 0 deletions build.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"math/rand"
"os"
"path/filepath"
"runtime"
"sort"
"strconv"
"strings"
Expand Down Expand Up @@ -268,6 +269,9 @@ func (b *BuildConfig) copyBuildpacksToContainer(ctx context.Context, ctrID strin
for _, bp := range b.Buildpacks {
var id, version string
if _, err := os.Stat(filepath.Join(bp, "buildpack.toml")); !os.IsNotExist(err) {
if runtime.GOOS == "windows" {
return nil, fmt.Errorf("directory buildpacks are not implemented on windows")
}
var buildpackTOML struct {
Buildpack struct {
ID string `toml:"id"`
Expand Down
30 changes: 20 additions & 10 deletions build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"os"
"path/filepath"
"regexp"
"runtime"
"strings"
"testing"
"time"
Expand Down Expand Up @@ -77,7 +78,7 @@ func testBuild(t *testing.T, when spec.G, it spec.S) {
})
it.After(func() {
for _, volName := range []string{subject.WorkspaceVolume, subject.CacheVolume} {
h.AssertNil(t, dockerCli.VolumeRemove(context.TODO(), volName, true))
dockerCli.VolumeRemove(context.TODO(), volName, true)
}
})

Expand Down Expand Up @@ -324,7 +325,7 @@ func testBuild(t *testing.T, when spec.G, it spec.S) {
_, err = envFile.Write([]byte(`
VAR1=value1
VAR2=value2 with spaces
USER
PATH
`))
h.AssertNil(t, err)
envFile.Close()
Expand All @@ -338,9 +339,9 @@ USER
h.AssertEq(t, config.EnvFile, map[string]string{
"VAR1": "value1",
"VAR2": "value2 with spaces",
"USER": os.Getenv("USER"),
"PATH": os.Getenv("PATH"),
})
h.AssertNotEq(t, os.Getenv("USER"), "")
h.AssertNotEq(t, os.Getenv("PATH"), "")
})
})

Expand All @@ -367,7 +368,7 @@ USER
var badappDir string
it.Before(func() {
var err error
badappDir, err = ioutil.TempDir("/tmp", "pack.build.badapp.")
badappDir, err = ioutil.TempDir("", "pack.build.badapp.")
h.AssertNil(t, err)
h.AssertNil(t, ioutil.WriteFile(filepath.Join(badappDir, "file.txt"), []byte("content"), 0644))
subject.AppDir = badappDir
Expand All @@ -385,8 +386,11 @@ USER
when("directory buildpack", func() {
var bpDir string
it.Before(func() {
if runtime.GOOS == "windows" {
t.Skip("directory buildpacks are not implemented on windows")
}
var err error
bpDir, err = ioutil.TempDir("/tmp", "pack.build.bpdir.")
bpDir, err = ioutil.TempDir("", "pack.build.bpdir.")
h.AssertNil(t, err)
h.AssertNil(t, ioutil.WriteFile(filepath.Join(bpDir, "buildpack.toml"), []byte(`
[buildpack]
Expand Down Expand Up @@ -432,7 +436,7 @@ USER

when("#Analyze", func() {
it.Before(func() {
tmpDir, err := ioutil.TempDir("/tmp", "pack.build.analyze.")
tmpDir, err := ioutil.TempDir("", "pack.build.analyze.")
h.AssertNil(t, err)
defer os.RemoveAll(tmpDir)
h.AssertNil(t, ioutil.WriteFile(filepath.Join(tmpDir, "group.toml"), []byte(`[[buildpacks]]
Expand Down Expand Up @@ -533,7 +537,7 @@ USER
var bpDir string
it.Before(func() {
var err error
bpDir, err = ioutil.TempDir("/tmp", "pack.build.bpdir.")
bpDir, err = ioutil.TempDir("", "pack.build.bpdir.")
h.AssertNil(t, err)
h.AssertNil(t, ioutil.WriteFile(filepath.Join(bpDir, "buildpack.toml"), []byte(`
[buildpack]
Expand All @@ -556,6 +560,9 @@ USER
it.After(func() { os.RemoveAll(bpDir) })

it("runs the buildpacks bin/build", func() {
if runtime.GOOS == "windows" {
t.Skip("directory buildpacks are not implemented on windows")
}
subject.Buildpacks = []string{bpDir}
_, err := subject.Detect()
h.AssertNil(t, err)
Expand All @@ -582,6 +589,9 @@ USER

when("EnvFile is specified", func() {
it("sets specified env variables in /platform/env/...", func() {
if runtime.GOOS == "windows" {
t.Skip("directory buildpacks are not implemented on windows")
}
subject.EnvFile = map[string]string{
"VAR1": "value1",
"VAR2": "value2 with spaces",
Expand All @@ -606,7 +616,7 @@ USER
runTopLayer string
)
it.Before(func() {
tmpDir, err := ioutil.TempDir("/tmp", "pack.build.export.")
tmpDir, err := ioutil.TempDir("", "pack.build.export.")
h.AssertNil(t, err)
defer os.RemoveAll(tmpDir)
files := map[string]string{
Expand Down Expand Up @@ -820,7 +830,7 @@ func runInImage(t *testing.T, dockerCli *docker.Client, volumes []string, repoNa
Binds: volumes,
}, nil, "")
h.AssertNil(t, err)
defer dockerCli.ContainerRemove(ctx, ctr.ID, dockertypes.ContainerRemoveOptions{})
defer dockerCli.ContainerRemove(ctx, ctr.ID, dockertypes.ContainerRemoveOptions{Force: true})

var buf bytes.Buffer
err = dockerCli.RunContainer(ctx, ctr.ID, &buf, &buf)
Expand Down
5 changes: 5 additions & 0 deletions cmd/pack/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"log"
"os"
"os/signal"
"runtime"
"strings"
"syscall"

Expand Down Expand Up @@ -143,6 +144,10 @@ func createBuilderCommand() *cobra.Command {
cmd.SilenceUsage = true
flags.RepoName = args[0]

if runtime.GOOS == "windows" {
return fmt.Errorf("create builder is not implemented on windows")
}

docker, err := docker.New()
if err != nil {
return err
Expand Down
4 changes: 4 additions & 0 deletions create_builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"math/rand"
"net/http"
"path/filepath"
"runtime"
"testing"
"time"

Expand All @@ -27,6 +28,9 @@ import (
)

func TestCreateBuilder(t *testing.T) {
if runtime.GOOS == "windows" {
t.Skip("create builder is not implemented on windows")
}
spec.Run(t, "create-builder", testCreateBuilder, spec.Sequential(), spec.Report(report.Terminal{}))
}

Expand Down
36 changes: 20 additions & 16 deletions fs/tar_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"math/rand"
"os"
"path/filepath"
"runtime"
"testing"
"time"

Expand Down Expand Up @@ -52,6 +53,7 @@ func testFS(t *testing.T, when spec.G, it spec.S) {
if err != nil {
t.Fatalf("could not open tar file %s: %s", tarFile, err)
}
defer file.Close()
gzr, err := gzip.NewReader(file)
tr := tar.NewReader(gzr)

Expand All @@ -75,23 +77,25 @@ func testFS(t *testing.T, when spec.G, it spec.S) {
t.Fatalf(`expected some-file.txt to be group 2345 was %d`, header.Gid)
}

t.Log("handles symlinks")
header, err = tr.Next()
if err != nil {
t.Fatalf("Failed to get next file: %s", err)
}
if header.Name != "/dir-in-archive/sub-dir/link-file" {
t.Fatalf(`expected file with name /dir-in-archive/sub-dir/link-file, got %s`, header.Name)
}
if header.Uid != 1234 {
t.Fatalf(`expected link-file to be owned by 1234 was %d`, header.Uid)
}
if header.Gid != 2345 {
t.Fatalf(`expected link-file to be group 2345 was %d`, header.Gid)
}
if runtime.GOOS != "windows" {
t.Log("handles symlinks")
header, err = tr.Next()
if err != nil {
t.Fatalf("Failed to get next file: %s", err)
}
if header.Name != "/dir-in-archive/sub-dir/link-file" {
t.Fatalf(`expected file with name /dir-in-archive/sub-dir/link-file, got %s`, header.Name)
}
if header.Uid != 1234 {
t.Fatalf(`expected link-file to be owned by 1234 was %d`, header.Uid)
}
if header.Gid != 2345 {
t.Fatalf(`expected link-file to be group 2345 was %d`, header.Gid)
}

if header.Linkname != "../some-file.txt" {
t.Fatalf(`expected to link-file to have atrget "../some-file.txt" got %s`, header.Linkname)
if header.Linkname != "../some-file.txt" {
t.Fatalf(`expected to link-file to have atrget "../some-file.txt" got "%s"`, header.Linkname)
}
}
})
}
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
cloud.google.com/go v0.25.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
github.com/Azure/azure-sdk-for-go v19.1.0+incompatible/go.mod h1:9XXNKU+eRnpl9moKnB4QOLf1HestfXbmab5FXxiDBjc=
github.com/Azure/go-ansiterm v0.0.0-20170929234023-d6e3b3328b78 h1:w+iIsaOQNcT7OZ575w+acHgRric5iCyQh+xv+KJ4HB8=
github.com/Azure/go-ansiterm v0.0.0-20170929234023-d6e3b3328b78/go.mod h1:LmzpDX56iTiv29bbRTIsUNlaFfuhWRQBWjQdVyAevI8=
github.com/Azure/go-autorest v10.15.0+incompatible/go.mod h1:r+4oMnoxhatjLLJ6zxSWATqVooLgysK6ZNox3g/xq24=
github.com/BurntSushi/toml v0.3.0 h1:e1/Ivsx3Z0FVTV0NSOv/aVgbUWyQuzj7DDnFblkRvsY=
Expand Down Expand Up @@ -151,6 +152,7 @@ golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/time v0.0.0-20180412165947-fbb02b2291d2 h1:+DCIGbF/swA92ohVg0//6X2IVY3KZs6p9mix0ziNYJM=
golang.org/x/time v0.0.0-20180412165947-fbb02b2291d2/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/time v0.0.0-20181108054448-85acf8d2951c h1:fqgJT0MGcGpPgpWU7VRdRjuArfcOvC4AoJmILihzhDg=
golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/tools v0.0.0-20180828015842-6cd1fcedba52/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM=
Expand Down

0 comments on commit eba23ce

Please sign in to comment.