Skip to content

Commit

Permalink
chore: build on arm64 and amd64 (#1040)
Browse files Browse the repository at this point in the history
  • Loading branch information
goenning committed Dec 24, 2021
1 parent e46e14e commit 0eae211
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 53 deletions.
8 changes: 6 additions & 2 deletions .github/workflows/build.yml
Expand Up @@ -25,6 +25,10 @@ jobs:
test-server:
name: test-server
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
arch: [x86_64, arm64]
services:
minio:
image: getfider/minio:0.0.2
Expand Down Expand Up @@ -67,6 +71,7 @@ jobs:
BLOB_STORAGE_S3_ENDPOINT_URL: http://localhost:9000
DATABASE_URL: postgres://fider_ci:fider_ci_pw@localhost:5432/fider_ci?sslmode=disable

# The build job uses the Dockerfile to build an image which is then used by e2e tests
build:
name: build
runs-on: ubuntu-latest
Expand All @@ -79,7 +84,7 @@ jobs:
echo sha7=${GITHUB_SHA::7}
id: vars

- run: docker build --build-arg buildnumber=${{ steps.vars.outputs.sha7 }} -t fider-image .
- run: docker build -t fider-image .

- run: mkdir -p ./out

Expand All @@ -89,7 +94,6 @@ jobs:
if: ${{ github.event_name == 'pull_request' }}

- run: echo ${{ steps.vars.outputs.sha7 }} > ./out/sha7
if: ${{ github.event_name == 'push' }}

- uses: actions/upload-artifact@v2
with:
Expand Down
54 changes: 23 additions & 31 deletions .github/workflows/publish.yml
Expand Up @@ -16,45 +16,37 @@ jobs:
env:
GITHUB_CONTEXT: ${{ toJSON(github) }}

- name: download artifact
uses: actions/github-script@v3.1.0
- name: Checkout
uses: actions/checkout@v2
with:
script: |
var artifacts = await github.actions.listWorkflowRunArtifacts({
owner: context.repo.owner,
repo: context.repo.repo,
run_id: ${{github.event.workflow_run.id }},
});
var matchArtifact = artifacts.data.artifacts.filter((artifact) => {
return artifact.name == "fider-image"
})[0];
var download = await github.actions.downloadArtifact({
owner: context.repo.owner,
repo: context.repo.repo,
artifact_id: matchArtifact.id,
archive_format: 'zip',
});
var fs = require('fs');
fs.writeFileSync('${{github.workspace}}/fider-image.zip', Buffer.from(download.data));
- run: unzip fider-image.zip
- run: docker load --input fider-image.tar
ref: ${{ github.event.workflow_run.head_sha }}

- name: Set up QEMU
uses: docker/setup-qemu-action@v1

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1

- name: Login to Docker Hub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKER_USER }}
password: ${{ secrets.DOCKER_PASS }}

- name: push docker image (pull_request)
- name: build and push docker image (pull_request)
if: ${{ github.event.workflow_run.event == 'pull_request' }}
run: |
docker tag fider-image getfider/fider:PR_$(cat ./pr)
docker push getfider/fider:PR_$(cat ./pr)
uses: docker/build-push-action@v2
with:
push: true
build-args: BUILDNUMBER=${{ github.event.workflow_run.head_sha }}
platforms: linux/amd64,linux/arm64/v8
tags: getfider/fider:PR_${{ github.event.workflow_run.pull_requests[0].number }}

- name: push docker image (push)
- name: build and push docker image (push)
if: ${{ github.event.workflow_run.event == 'push' }}
run: |
docker tag fider-image getfider/fider:SHA_$(cat ./sha7)
docker push getfider/fider:SHA_$(cat ./sha7)
docker tag fider-image getfider/fider:main
docker push getfider/fider:main
uses: docker/build-push-action@v2
with:
push: true
build-args: BUILDNUMBER=${{ github.event.workflow_run.head_sha }}
platforms: linux/amd64,linux/arm64/v8
tags: getfider/fider:SHA_${{ github.event.workflow_run.head_sha }},getfider/fider:main
14 changes: 7 additions & 7 deletions Dockerfile
@@ -1,22 +1,23 @@
#####################
### Server Build Step
#####################
FROM golang:1.17-buster AS server-builder
FROM --platform=${TARGETPLATFORM:-linux/amd64} golang:1.17-buster AS server-builder

ARG buildnumber=local
ARG BUILDNUMBER=local
ARG TARGETOS
ARG TARGETARCH

RUN mkdir /server
WORKDIR /server

COPY . .
RUN BUILDNUMBER=${buildnumber} GOOS=linux GOARCH=amd64 make build-server
RUN BUILDNUMBER=${BUILDNUMBER} GOOS=${TARGETOS} GOARCH=${TARGETARCH} make build-server

#################
### UI Build Step
#################
FROM node:16-buster AS ui-builder
FROM --platform=${TARGETPLATFORM:-linux/amd64} node:16-buster AS ui-builder

RUN mkdir /ui
WORKDIR /ui

COPY . .
Expand All @@ -27,12 +28,11 @@ RUN make build-ui
################
### Runtime Step
################
FROM debian:buster-slim
FROM --platform=${TARGETPLATFORM:-linux/amd64} debian:buster-slim

RUN apt-get update
RUN apt-get install -y ca-certificates

RUN mkdir /app
WORKDIR /app

COPY --from=server-builder /server/migrations /app/migrations
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Expand Up @@ -78,7 +78,7 @@ watch-ui: ## Build and run server in watch mode
lint: lint-server lint-ui ## Lint server and ui

lint-server: ## Lint server code
golangci-lint run
golangci-lint run --timeout 2m

lint-ui: ## Lint ui code
npx eslint .
Expand Down
12 changes: 3 additions & 9 deletions app/pkg/web/react.go
Expand Up @@ -22,10 +22,7 @@ type ReactRenderer struct {
func newIsolatePool() *sync.Pool {
return &sync.Pool{
New: func() interface{} {
isolate, err := v8go.NewIsolate()
if err != nil {
return errors.Wrap(err, "unable to initialize v8 isolate.")
}
isolate := v8go.NewIsolate()

runtime.SetFinalizer(isolate, func(iso *v8go.Isolate) {
if iso != nil {
Expand Down Expand Up @@ -60,13 +57,10 @@ func (r *ReactRenderer) Render(u *url.URL, props Map) (string, error) {
}
defer r.pool.Put(isolate)

v8ctx, err := v8go.NewContext(isolate)
if err != nil {
return "", errors.Wrap(err, "unable to initialize v8 context.")
}
v8ctx := v8go.NewContext(isolate)
defer v8ctx.Close()

_, err = v8ctx.RunScript(string(r.scriptContent), r.scriptPath)
_, err := v8ctx.RunScript(string(r.scriptContent), r.scriptPath)
if err != nil {
return "", errors.Wrap(err, "failed to execute SSR script.")
}
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Expand Up @@ -26,7 +26,7 @@ require (
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519
golang.org/x/net v0.0.0-20211029224645-99673261e6eb
golang.org/x/oauth2 v0.0.0-20211028175245-ba495a64dcb5
rogchap.com/v8go v0.6.0
rogchap.com/v8go v0.7.1-0.20211222173054-943fcf9e74cc
)

require (
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Expand Up @@ -1417,8 +1417,8 @@ mvdan.cc/lint v0.0.0-20170908181259-adc824a0674b/go.mod h1:2odslEg/xrtNQqCYg2/jC
mvdan.cc/unparam v0.0.0-20210104141923-aac4ce9116a7/go.mod h1:hBpJkZE8H/sb+VRFvw2+rBpHNsTBcvSpk61hr8mzXZE=
mvdan.cc/unparam v0.0.0-20211002134041-24922b6997ca h1:xzXXnoG5a3NUnKAcVMpE2cs3+RwR5/R+jtvLPFoNw7I=
mvdan.cc/unparam v0.0.0-20211002134041-24922b6997ca/go.mod h1:Mb96j26qXgU/+SOj6MSgC36X30UgAlRYaxckYuYyEmo=
rogchap.com/v8go v0.6.0 h1:wNn5Iu06+ke7HM511zXTVBBpRNYaauyZoPMTrLsGurU=
rogchap.com/v8go v0.6.0/go.mod h1:IitZnaOtWSJadY/7qinKHIEHpxsilMWyLQ+Efdo4n4I=
rogchap.com/v8go v0.7.1-0.20211222173054-943fcf9e74cc h1:rcoe6etpGGPcdMibCdCI38v0Th/oyxqTFAjnMQiDGnY=
rogchap.com/v8go v0.7.1-0.20211222173054-943fcf9e74cc/go.mod h1:MxgP3pL2MW4dpme/72QRs8sgNMmM0pRc8DPhcuLWPAs=
rsc.io/binaryregexp v0.2.0/go.mod h1:qTv7/COck+e2FymRvadv62gMdZztPaShugOCi3I+8D8=
rsc.io/quote/v3 v3.1.0/go.mod h1:yEA65RcK8LyAZtP9Kv3t0HmxON59tX3rD+tICJqUlj0=
rsc.io/sampler v1.3.0/go.mod h1:T1hPZKmBbMNahiBKFy5HrXp6adAjACjK9JXDnKaTXpA=
Expand Down

0 comments on commit 0eae211

Please sign in to comment.