From 0f6baf3248edb27ebe5cf0fb2f364aa7d6d79b11 Mon Sep 17 00:00:00 2001 From: Yuval Kohavi Date: Sun, 17 May 2020 15:16:55 -0400 Subject: [PATCH] small fixes (#65) * small fixes * allow release * mini typo * publish releases to quay * push docker --- .github/workflows/pull_request.yaml | 72 +++++++++++++++++++++++++++++ README.md | 10 ++-- cloudbuild.yaml | 22 --------- go.sum | 1 + pkg/flasher/flash.go | 2 + pkg/utils/copy.go | 6 ++- 6 files changed, 85 insertions(+), 28 deletions(-) create mode 100644 .github/workflows/pull_request.yaml delete mode 100644 cloudbuild.yaml diff --git a/.github/workflows/pull_request.yaml b/.github/workflows/pull_request.yaml new file mode 100644 index 00000000..563ad03d --- /dev/null +++ b/.github/workflows/pull_request.yaml @@ -0,0 +1,72 @@ +name: pull_request + +on: + push: + branches: + - 'master' + pull_request: {} + release: + types: [published] +env: + TAGGED_VERSION: ${{github.event.release.tag_name || '' }} + +jobs: + build: + name: build-works + runs-on: ubuntu-18.04 + steps: + - uses: actions/checkout@v2 + - name: Set up Go 1.14 + uses: actions/setup-go@v2 + with: + go-version: 1.14 + - uses: actions/cache@v1 + with: + path: ~/go/pkg/mod + key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} + restore-keys: | + ${{ runner.os }}-go- + - name: Generate code + run: | + go install github.com/hashicorp/packer/cmd/mapstructure-to-hcl2 + go generate ./... + if [[ $(git status --porcelain | wc -l) -ne 0 ]]; then + echo "Generating code produced a non-empty diff" + echo "Try running 'go install github.com/hashicorp/packer/cmd/mapstructure-to-hcl2 && go generate ./...' then re-pushing." + git status --porcelain + git diff | cat + exit 1; + fi + - name: Build + run: | + go build -o packer-builder-arm-image . + go build -o flasher github.com/solo-io/packer-builder-arm-image/cmd/flasher + docker build -t packer-builder-arm-image . + - name: Release packer-builder-arm-image + if: github.event.release.tag_name + uses: actions/upload-release-asset@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + upload_url: ${{ github.event.release.upload_url }} + asset_path: ./packer-builder-arm-image + asset_name: packer-builder-arm-image + asset_content_type: application/octet-stream + - name: Release flasher + if: github.event.release.tag_name + uses: actions/upload-release-asset@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + upload_url: ${{ github.event.release.upload_url }} + asset_path: ./flasher + asset_name: flasher + asset_content_type: application/octet-stream + - name: Push docker + if: github.event.release.tag_name + env: + QUAY_IO_PASSWORD: ${{ secrets.QUAY_IO_PASSWORD }} + run: | + docker login quay.io --username "solo-io+solobot" --password $QUAY_IO_PASSWORD + docker tag packer-builder-arm-image quay.io/solo-io/packer-builder-arm-image:${TAGGED_VERSION} + docker push quay.io/solo-io/packer-builder-arm-image:${TAGGED_VERSION} \ No newline at end of file diff --git a/README.md b/README.md index 75f02c49..d357431f 100644 --- a/README.md +++ b/README.md @@ -110,7 +110,9 @@ docker run \ -v ${PWD}:/build:ro \ -v ${PWD}/packer_cache:/build/packer_cache \ -v ${PWD}/output-arm-image:/build/output-arm-image \ - packer-builder-arm build samples/raspbian_golang.json + -e PACKER_CACHE_DIR=/build/packer_cache \ + -w /build/samples/hostapd/ \ + packer-builder-arm build raspbian_hostapd.json ``` Alternativly, you can use the `docker.pkg.github.com/solo-io/packer-builder-arm-image/packer-builder-arm` that's built off latest master: @@ -228,9 +230,9 @@ this example requires you to run the plugin without a VM, as it copies your loca { "type": "shell", "inline": [ - "sed '/PasswordAuthentication/d' -i /etc/ssh/ssh_config", - "echo >> /etc/ssh/ssh_config", - "echo 'PasswordAuthentication no' >> /etc/ssh/ssh_config" + "sed '/PasswordAuthentication/d' -i /etc/ssh/sshd_config", + "echo >> /etc/ssh/sshd_config", + "echo 'PasswordAuthentication no' >> /etc/ssh/sshd_config" ] } ] diff --git a/cloudbuild.yaml b/cloudbuild.yaml deleted file mode 100644 index 9ecbb5ec..00000000 --- a/cloudbuild.yaml +++ /dev/null @@ -1,22 +0,0 @@ -steps: - -- name: 'gcr.io/cloud-builders/go' - args: ['build', "-o", "packer-builder-arm-image"] - env: - - PROJECT_ROOT=github.com/solo-io/packer-builder-arm-image - -- name: 'gcr.io/cloud-builders/go' - args: ['build', "-o", "cmd/flasher/flasher", "github.com/solo-io/packer-builder-arm-image/cmd/flasher"] - env: - - PROJECT_ROOT=github.com/solo-io/packer-builder-arm-image - -- name: 'gcr.io/$PROJECT_ID/go-make' - entrypoint: ./hack/upload.sh - secretEnv: ['GITHUB_TOKEN'] - env: - - TAG_NAME=$TAG_NAME - -secrets: -- kmsKeyName: projects/solo-public/locations/global/keyRings/build/cryptoKeys/build-key - secretEnv: - GITHUB_TOKEN: CiQABlzmSQhtCq6661EaOys3Rz5P0/10ttglSaFN9lzaFCxnorASUQCCPGSGDE62fGJrtCucLxt29e1fTZtUCa0CqnwLi0xNNWiaNSRaYiazWMdwnUFO5wcMHz/7B+84tOzZZOVgh6iz2HoYy13b4iTmymj3xUsFRA== diff --git a/go.sum b/go.sum index 934950b1..cd240e66 100644 --- a/go.sum +++ b/go.sum @@ -58,6 +58,7 @@ github.com/antchfx/xquery v0.0.0-20170730121040-eb8c3c172607/go.mod h1:LzD22aAzD github.com/antihax/optional v0.0.0-20180407024304-ca021399b1a6 h1:uZuxRZCz65cG1o6K/xUqImNcYKtmk9ylqaH0itMSvzA= github.com/antihax/optional v0.0.0-20180407024304-ca021399b1a6/go.mod h1:V8iCPQYkqmusNa815XgQio277wI47sdRh1dUOLdyC6Q= github.com/antihax/optional v1.0.0/go.mod h1:uupD/76wgC+ih3iEmQUL+0Ugr19nfwCT1kdvxnR2qWY= +github.com/apparentlymart/go-dump v0.0.0-20180507223929-23540a00eaa3 h1:ZSTrOEhiM5J5RFxEaFvMZVEAM1KvT1YzbEOwB2EAGjA= github.com/apparentlymart/go-dump v0.0.0-20180507223929-23540a00eaa3/go.mod h1:oL81AME2rN47vu18xqj1S1jPIPuN7afo62yKTNn3XMM= github.com/apparentlymart/go-textseg v1.0.0 h1:rRmlIsPEEhUTIKQb7T++Nz/A5Q6C9IuX2wFoYVvnCs0= github.com/apparentlymart/go-textseg v1.0.0/go.mod h1:z96Txxhf3xSFMPmb5X/1W05FF/Nj9VFpLOpjS5yuumk= diff --git a/pkg/flasher/flash.go b/pkg/flasher/flash.go index 93cb7d86..d7bb9ac4 100644 --- a/pkg/flasher/flash.go +++ b/pkg/flasher/flash.go @@ -80,10 +80,12 @@ func (f *flasher) Flash(ctx context.Context) error { } } + f.ui.Say("Unmounting device " + dev.Device) err = f.unmount(dev) if err != nil { return err } + f.ui.Say("Flashing device " + dev.Device) res, err := f.flash(ctx, imageToFlash, dev) if err != nil { return err diff --git a/pkg/utils/copy.go b/pkg/utils/copy.go index c2a22c46..2e567acf 100644 --- a/pkg/utils/copy.go +++ b/pkg/utils/copy.go @@ -24,15 +24,18 @@ func CopyWithProgress(ctx context.Context, ui packer.Ui, dst io.Writer, src io.R } else { l = NewProgressWriter() } + // this will cancel the Copy if still in progress when we leave the function + defer l.Stop() rdr := io.TeeReader(src, l) copyCompleteCh := make(chan copyResult, 1) go func() { + defer close(copyCompleteCh) n, err := io.Copy(dst, rdr) copyCompleteCh <- copyResult{n: n, err: err} }() - progressTicker := time.NewTicker(15 * time.Second) + progressTicker := time.NewTicker(5 * time.Second) defer progressTicker.Stop() for { @@ -48,7 +51,6 @@ func CopyWithProgress(ctx context.Context, ui packer.Ui, dst io.Writer, src io.R ui.Message(fmt.Sprintf("Progress: %3.2f%%", progress.PercentDone)) } case <-ctx.Done(): - l.Stop() return int64(l.TotalData()), errors.New("interrupted") } }