diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 00000000..76ed5be3 --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,77 @@ +name: build +on: + push: + tags: + - v* + branches: + - main + pull_request: + branches: + - main + +concurrency: + group: ${{ github.workflow }}-${{ github.event.number || github.ref }} + cancel-in-progress: true + +env: + # renovate: datasource=go depName=github.com/golangci/golangci-lint + GOLANGCI_LINT_VERSION: v1.52.2 + +jobs: + spellcheck: + name: Spell Check + runs-on: ubuntu-latest + steps: + - name: Checkout Actions Repository + uses: actions/checkout@v2 + + - name: Check spelling of Go files + uses: crate-ci/typos@master + with: + files: '*.go' + write_changes: true + + golangci-lint: + name: Go Lint + runs-on: ubuntu-latest + timeout-minutes: 30 + steps: + - uses: actions/checkout@v3 + + - name: Configure git for private modules + env: + TOKEN: ${{ secrets.PAT }} + run: git config --global url."https://Pryz:${TOKEN}@github.com".insteadOf "https://github.com" + + - name: Set up Go + uses: actions/setup-go@v3 + with: + go-version-file: .go-version + check-latest: true + cache: true + + - name: golangci-lint + uses: golangci/golangci-lint-action@v3 + with: + version: ${{ env.GOLANGCI_LINT_VERSION }} + args: --timeout 5m + + test: + name: Go Test + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + + - name: Configure git for private modules + env: + TOKEN: ${{ secrets.PAT }} + run: git config --global url."https://Pryz:${TOKEN}@github.com".insteadOf "https://github.com" + + - name: Set up Go + uses: actions/setup-go@v3 + with: + go-version-file: .go-version + check-latest: true + + - name: Test + run: go test -v ./... diff --git a/.go-version b/.go-version new file mode 100644 index 00000000..0bd54efd --- /dev/null +++ b/.go-version @@ -0,0 +1 @@ +1.20.4 diff --git a/.golangci.yml b/.golangci.yml new file mode 100644 index 00000000..11b4c094 --- /dev/null +++ b/.golangci.yml @@ -0,0 +1,38 @@ +run: + deadline: 7m + timeout: 5m + go: '1.20' + +linters: + enable: + - depguard + - godot + - gofumpt + - goimports + - revive + - whitespace + +issues: + exclude-rules: + - path: _test.go + linters: + - errcheck + +linters-settings: + depguard: + list-type: blacklist + include-go-root: true + packages-with-error-message: [] + errcheck: + goimports: + local-prefixes: github.com/stealthrocket/wzprof + gofumpt: + extra-rules: true + misspell: + locale: US + revive: + rules: + # https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#unexported-return + - name: unexported-return + severity: warning + disabled: true diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..13f0614b --- /dev/null +++ b/Dockerfile @@ -0,0 +1,26 @@ +FROM golang:1.20-alpine as build + +RUN apk update && apk add make git gcc libc-dev curl + +WORKDIR /go/src/github.com/stealthrocket/timecraft +COPY . . + +ARG version +ARG tags +ARG gocache + +RUN go build -o timecraft + +# The last layer of the build, which determines what the final docker image +# will contain. +FROM alpine + +RUN apk update && apk add ca-certificates curl bind-tools tree + +ENV TIMECRAFT_BIND=:8080 + +EXPOSE 8080/tcp + +COPY --from=build /go/src/github.com/stealthrocket/timecraft/timecraft /usr/bin/timecraft + +ENTRYPOINT ["timecraft"] diff --git a/cmd/run.go b/cmd/run.go index 903a047c..a6bfa97e 100644 --- a/cmd/run.go +++ b/cmd/run.go @@ -10,9 +10,9 @@ import ( "time" "github.com/spf13/cobra" - "github.com/stealthrocket/wasi" - "github.com/stealthrocket/wasi/imports/wasi_snapshot_preview1" - "github.com/stealthrocket/wasi/wasiunix" + "github.com/stealthrocket/wasi-go" + "github.com/stealthrocket/wasi-go/imports/wasi_snapshot_preview1" + "github.com/stealthrocket/wasi-go/systems/unix" "github.com/stealthrocket/wazergo" "github.com/tetratelabs/wazero" "github.com/tetratelabs/wazero/sys" @@ -47,7 +47,7 @@ func run(ctx context.Context, args []string) error { environ = append(environ, "PWD="+wd) } - provider := &wasiunix.Provider{ + provider := &unix.System{ Args: append([]string{wasmName}, args[1:]...), Environ: environ, Realtime: realtime, diff --git a/go.mod b/go.mod index 3c780345..1aedcd92 100644 --- a/go.mod +++ b/go.mod @@ -7,7 +7,7 @@ require ( github.com/google/go-cmp v0.5.9 github.com/klauspost/compress v1.16.5 github.com/spf13/cobra v1.7.0 - github.com/stealthrocket/wasi v0.0.0-20230504000138-9d2008307ac8 + github.com/stealthrocket/wasi-go v0.0.0-20230508014825-d291ccc8185a github.com/stealthrocket/wazergo v0.17.1 github.com/tetratelabs/wazero v1.1.0 ) diff --git a/go.sum b/go.sum index 9eda9dc7..c69ee61d 100644 --- a/go.sum +++ b/go.sum @@ -12,8 +12,8 @@ github.com/spf13/cobra v1.7.0 h1:hyqWnYt1ZQShIddO5kBpj3vu05/++x6tJ6dg8EC572I= github.com/spf13/cobra v1.7.0/go.mod h1:uLxZILRyS/50WlhOIKD7W6V5bgeIt+4sICxh6uRMrb0= github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA= github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= -github.com/stealthrocket/wasi v0.0.0-20230504000138-9d2008307ac8 h1:WJVwrOL+OsVij6NM5vTb7iU5KoE3YgbPdD5rh4PfIm4= -github.com/stealthrocket/wasi v0.0.0-20230504000138-9d2008307ac8/go.mod h1:6GDKyiPuzLz3LJ91aGvrw9qca7XXAANIyiGMGRnujHo= +github.com/stealthrocket/wasi-go v0.0.0-20230508014825-d291ccc8185a h1:qf504FlX3/eGQgjDfCB9/uZtH/3i7w7lpx3B9bDWMfY= +github.com/stealthrocket/wasi-go v0.0.0-20230508014825-d291ccc8185a/go.mod h1:cSfmIlZZjwC6SoxMEsWVEcC2eSUQhfZQOdB99rKKAr8= github.com/stealthrocket/wazergo v0.17.1 h1:lXx4/Lg1A+9ATZWYI0J2E4oWfihhOLxWfnAT2Wy8iKQ= github.com/stealthrocket/wazergo v0.17.1/go.mod h1:riI0hxw4ndZA5e6z7PesHg2BtTftcZaMxRcoiGGipTs= github.com/tetratelabs/wazero v1.1.0 h1:EByoAhC+QcYpwSZJSs/aV0uokxPwBgKxfiokSUwAknQ=