Skip to content

Commit

Permalink
Upgrade go to 1.19 and build multi-platform docker image (#260)
Browse files Browse the repository at this point in the history
Also:
- bump arr-ai/frozen to latest
- upgrade linter to latest and fix all the linting errors
- remove go-bindata (replace with embed)
  • Loading branch information
AriehSchneier authored Aug 18, 2022
1 parent fb391b2 commit ad27e8c
Show file tree
Hide file tree
Showing 47 changed files with 262 additions and 416 deletions.
57 changes: 39 additions & 18 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,34 +17,55 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Check out code
uses: actions/checkout@master
uses: actions/checkout@v3

- name: Docker meta
id: meta
uses: docker/metadata-action@v4
with:
images: |
docker.io/anzbank/arrai
tags: |
type=ref,event=branch
type=ref,event=pr
type=semver,pattern={{version}}
type=sha
labels: |
org.opencontainers.image.url=https://arr.ai
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2

- name: Build docker container image
uses: docker/build-push-action@v1
uses: docker/build-push-action@v3
with:
repository: docker.io/anzbank/arrai
context: .
load: true
push: false
tag_with_ref: true
add_git_labels: true
tags: latest
labels: org.opencontainers.image.revision=${{ github.sha }},org.opencontainers.image.url=https://arr.ai
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}

- name: Test container image
uses: plexsystems/container-structure-test-action@v0.1.0
with:
# this is intended to resolve to the local docker image we just built above
image: anzbank/arrai:latest
image: ${{ fromJSON(steps.meta.outputs.json).tags[0] }}
config: container-structure-tests.yaml

- name: Build and push docker container image
uses: docker/build-push-action@v1
- name: Login to DockerHub
# only attempt to push if we are in the open source repo that has credentials, and there's been a push, not merely a pull request.
if: github.repository == 'arr-ai/arrai' && github.event_name == 'push'
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKER_USER }}
password: ${{ secrets.DOCKER_PASS }}
repository: docker.io/anzbank/arrai
# only attempt to push if we are in the open source repo that has credentials, and there's been a push, not merely a pull request.
push: ${{ github.repository == 'arr-ai/arrai' && github.event_name == 'push'}}
tag_with_ref: true
add_git_labels: true
tags: latest
labels: org.opencontainers.image.revision=${{ github.sha }},org.opencontainers.image.url=https://arr.ai

- name: Build and push docker container image
# only attempt to push if we are in the open source repo that has credentials, and there's been a push, not merely a pull request.
if: github.repository == 'arr-ai/arrai' && github.event_name == 'push'
uses: docker/build-push-action@v3
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
platforms: linux/amd64,linux/arm64
4 changes: 2 additions & 2 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Check out code into the Go module directory
uses: actions/checkout@v2
uses: actions/checkout@v3

- name: Uses Node.js 14.x
uses: actions/setup-node@v1
uses: actions/setup-node@v3
with:
node-version: 14.x

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/generate-tag.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Check out code
uses: actions/checkout@master
uses: actions/checkout@v3
with:
fetch-depth: '0'

Expand Down
28 changes: 11 additions & 17 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,13 @@ jobs:
name: Lint
runs-on: ubuntu-latest
steps:
- name: Set up Go 1.16
- name: Set up Go 1.19
uses: actions/setup-go@v3
with:
go-version: 1.16

- name: Install go-bindata
run: go get github.com/anz-bank/go-bindata/...
go-version: 1.19

- name: Check out code into the Go module directory
uses: actions/checkout@v2
uses: actions/checkout@v3

- uses: Logerfo/newline-action@0.0.2
with:
Expand All @@ -25,18 +22,18 @@ jobs:
- name: Run golangci-lint
uses: golangci/golangci-lint-action@v3.1.0
with:
version: v1.41.1
version: v1.48.0

- name: Check clean
run: make check-clean

build:
name: Build
runs-on: ubuntu-latest
container: golang:1.16
container: golang:1.19
steps:
- name: Check out code into the Go module directory
uses: actions/checkout@v2
uses: actions/checkout@v3

- name: Get dependencies
run: go get -v -t -d ./...
Expand All @@ -51,27 +48,24 @@ jobs:
platform: [ubuntu-latest, macos-latest, windows-latest]
runs-on: ${{ matrix.platform }}
steps:
- name: Set up Go 1.16
- name: Set up Go 1.19
uses: actions/setup-go@v3
with:
go-version: 1.16

- name: Install go-bindata
run: go get github.com/anz-bank/go-bindata/...
go-version: 1.19

- name: Check out code into the Go module directory
uses: actions/checkout@v2
uses: actions/checkout@v3

- name: Run tests
run: make test

coverage:
name: Coverage
runs-on: ubuntu-latest
container: golang:1.16
container: golang:1.19
steps:
- name: Check out code into the Go module directory
uses: actions/checkout@v2
uses: actions/checkout@v3

- name: Calculate coverage
run: go test -v -covermode=atomic -coverprofile=coverage.out -race ./...
Expand Down
13 changes: 5 additions & 8 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,20 @@ jobs:
name: Release Arr.ai
runs-on: ubuntu-latest
steps:
- name: Set up Go 1.16
uses: actions/setup-go@v2
- name: Set up Go 1.19
uses: actions/setup-go@v3
with:
go-version: 1.16

- name: Install go-bindata
run: go get github.com/anz-bank/go-bindata/...
go-version: 1.19

- name: Check out code into the Go module directory
uses: actions/checkout@master
uses: actions/checkout@v3

- name: Unshallow
run: git fetch --prune --unshallow

- name: Install golangci-lint
run: |
go get github.com/golangci/golangci-lint/cmd/golangci-lint@v1.41.1
go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.48.0
git restore go.mod go.sum
- name: Build
Expand Down
12 changes: 6 additions & 6 deletions .github/workflows/wasm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ jobs:
name: Build and Test Wasm
runs-on: ubuntu-latest
steps:
- name: Set up Go 1.16
uses: actions/setup-go@v1
- name: Set up Go 1.19
uses: actions/setup-go@v3
with:
go-version: 1.16
go-version: 1.19
id: go

- name: Check out code into the Go module directory
uses: actions/checkout@v1
uses: actions/checkout@v3

- name: Get dependencies
run: go get -v -t -d ./...
Expand All @@ -27,7 +27,7 @@ jobs:
run: GOOS=js GOARCH=wasm go build -o arrai.wasm ./cmd/arrai

- name: Set up Node
uses: actions/setup-node@v1
uses: actions/setup-node@v3
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

Expand All @@ -40,7 +40,7 @@ jobs:
echo '**** env'
env
echo '**** node'
node $(go env GOROOT)/misc/wasm/wasm_exec.js arrai.wasm eval '1 + 5'
node $(go env GOROOT)/misc/wasm/wasm_exec_node.js arrai.wasm eval '1 + 5'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_AUTH_TOKEN: "SOME-RANDOM-KEY"
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
.idea/
~$*
syntax/*.arraiz
.vscode
8 changes: 5 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
FROM golang:alpine3.12 AS stage
ARG go_ver=1.19
ARG alpine_ver=3.16

FROM golang:${go_ver}-alpine${alpine_ver} AS stage
RUN apk add --no-cache make git
RUN go get github.com/anz-bank/go-bindata/...

WORKDIR /usr/arrai
COPY . .
RUN make build

FROM golang:alpine3.12
FROM golang:${go_ver}-alpine${alpine_ver}
COPY --from=stage /usr/arrai/arrai /bin/arrai

ENTRYPOINT ["/bin/arrai"]
1 change: 1 addition & 0 deletions cmd/arrai/binaryinfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package main
// BuildDate - Binary build date
// GoVersion - Binary build GoVersion
// BuildOS - Operating System used to build binary
//
//nolint:gochecknoglobals
var (
Version = "unspecified"
Expand Down
4 changes: 2 additions & 2 deletions cmd/arrai/eval_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package main

import (
"context"
"io/ioutil"
"io"
"strings"
"testing"

Expand Down Expand Up @@ -31,7 +31,7 @@ func assertEvalCreates(t *testing.T, expected map[string]string, source, out str
for path, content := range expected {
fs, err := memFs.Open(path)
if assert.NoError(t, err) {
data, err := ioutil.ReadAll(fs)
data, err := io.ReadAll(fs)
if assert.NoError(t, err) && assert.Equal(t, content, string(data), "path=%s", path) {
continue
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/arrai/json.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package main
import (
"encoding/json"
"fmt"
"io/ioutil"
"io"
"os"

"github.com/sirupsen/logrus"
Expand All @@ -22,7 +22,7 @@ var jsonCommand = &cli.Command{
}

func fromJSON(cli *cli.Context) error {
raw, err := ioutil.ReadAll(os.Stdin)
raw, err := io.ReadAll(os.Stdin)
if err != nil {
return err
}
Expand Down
1 change: 1 addition & 0 deletions cmd/arrai/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ func serve(c *cli.Context) error {
}

wsFrontend := newWebsocketFrontend(eng)
//nolint:gosec
srv := &http.Server{
Addr: listen,
Handler: http.HandlerFunc(wsFrontend.ServeHTTP),
Expand Down
2 changes: 1 addition & 1 deletion docs/docs/lang/interop.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ val, err := syntax.EvaluateExpr(arraictx.InitRunCtx(context.Background()), "", "

The `arr.ai source` can be a string constant or loaded from a file. However loading sources dynamically can be complicated, since imports must still be resolved.

An alternative method is to use `arrai bundle` to produce an `arraiz` ZIP archive containing all necessary sources, compile that archive into a Go program (with e.g. [`go-bindata`](https://github.com/go-bindata/go-bindata)), and then run it with:
An alternative method is to use `arrai bundle` to produce an `arraiz` ZIP archive containing all necessary sources, compile that archive into a Go program (with e.g. [`embed`](https://pkg.go.dev/embed)), and then run it with:

```go
val, err := syntax.EvaluateBundle(arraictx.InitRunCtx(context.Background()), bundle, "", "arg", "...")
Expand Down
6 changes: 1 addition & 5 deletions examples/bundle/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,9 @@ tidy:
goimports -w .

# Builds the main binary, including the generated bindata.go.
main: internal/arrai/bindata.go
main: internal/arrai/echo.arraiz
go build -o main main.go && chmod +x main

# Generates bindata.go, containing a []byte constant for internal/arrai/echo.arraiz.
internal/arrai/bindata.go: internal/arrai/echo.arraiz
go-bindata -pkg arrai -o $@ $^

# Generates .arraiz files by calling arrai bundle on .arrai files.
%.arraiz: %.arrai
arrai bundle $< > $@
39 changes: 37 additions & 2 deletions examples/bundle/go.mod
Original file line number Diff line number Diff line change
@@ -1,10 +1,45 @@
module github.com/arr-ai/arrai/examples/bundle

go 1.15
go 1.18

require (
github.com/arr-ai/arrai v0.179.0
github.com/stretchr/testify v1.6.1
github.com/stretchr/testify v1.7.0
)

require (
github.com/anz-bank/pkg v0.0.22 // indirect
github.com/arr-ai/frozen v0.20.1 // indirect
github.com/arr-ai/hash v0.8.0 // indirect
github.com/arr-ai/wbnf v0.34.0 // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/go-errors/errors v1.4.0 // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/google/go-github/v32 v32.1.0 // indirect
github.com/google/go-querystring v1.0.0 // indirect
github.com/iancoleman/strcase v0.1.3 // indirect
github.com/mattn/go-isatty v0.0.12 // indirect
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/richardlehane/mscfb v1.0.3 // indirect
github.com/richardlehane/msoleps v1.0.1 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/sirupsen/logrus v1.8.1 // indirect
github.com/spf13/afero v1.3.5 // indirect
github.com/stretchr/objx v0.3.0 // indirect
github.com/urfave/cli/v2 v2.2.0 // indirect
github.com/xuri/efp v0.0.0-20210322160811-ab561f5b45e3 // indirect
github.com/xuri/excelize/v2 v2.4.1 // indirect
golang.org/x/crypto v0.0.0-20210711020723-a769d52b0f97 // indirect
golang.org/x/net v0.0.0-20210726213435-c6fcb2dbf985 // indirect
golang.org/x/oauth2 v0.0.0-20200902213428-5d25da1a8d43 // indirect
golang.org/x/sys v0.0.0-20210910150752-751e447fb3d0 // indirect
golang.org/x/text v0.3.7 // indirect
google.golang.org/appengine v1.6.6 // indirect
google.golang.org/protobuf v1.26.0 // indirect
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect
)

replace github.com/arr-ai/arrai => ../..
Loading

0 comments on commit ad27e8c

Please sign in to comment.