Skip to content

Commit

Permalink
chore: create multiarch docker image
Browse files Browse the repository at this point in the history
  • Loading branch information
abemedia committed Mar 28, 2021
1 parent b4a1f47 commit 64fbcd2
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 93 deletions.
35 changes: 23 additions & 12 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,25 +74,36 @@ jobs:
steps:
- uses: actions/checkout@v2

- name: Docker meta
id: docker_meta
uses: crazy-max/ghaction-docker-meta@v1
with:
images: getfider/fider
tag-sha: ${{ github.event.workflow_run.event == 'push' }}

- name: extract variables
run: |
echo "##[set-output name=sha7;]$(echo ${GITHUB_SHA::7})"
echo sha7=${GITHUB_SHA::7}
id: vars

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

- run: mkdir -p ./out
- name: Set up QEMU
uses: docker/setup-qemu-action@v1

- run: docker save -o ./out/fider.tar getfider/fider
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1

- run: echo ${{ github.event.number }} > ./out/pr
if: ${{ github.event_name == 'pull_request' }}

- run: echo ${{ steps.vars.outputs.sha7 }} > ./out/sha7
if: ${{ github.event_name == 'push' }}
- name: Login to DockerHub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKER_USER }}
password: ${{ secrets.DOCKER_PASS }}

- uses: actions/upload-artifact@v2
- name: Build and push
uses: docker/build-push-action@v2
with:
name: out
path: out/
push: true
build-args: buildnumber=${{ steps.vars.outputs.sha7 }}
platforms: linux/386,linux/amd64,linux/arm/v7,linux/arm64
tags: ${{ steps.docker_meta.outputs.tags }}
labels: ${{ steps.docker_meta.outputs.labels }}
59 changes: 0 additions & 59 deletions .github/workflows/publish.yml

This file was deleted.

11 changes: 6 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,21 @@
FROM golang:1.16.2-buster AS server-builder

ARG buildnumber=local
ARG TARGETPLATFORM

RUN mkdir /server
WORKDIR /server

COPY . .
RUN BUILDNUMBER=${buildnumber} GOOS=linux GOARCH=amd64 make build-server
RUN BUILDNUMBER=${buildnumber} \
GOARCH="$(echo $TARGETPLATFORM | cut -d '/' -f 2)" \
GOARM="$(echo $TARGETPLATFORM | cut -d '/' -f 3 | tail -c 2)" \
CGO_ENABLED=0 GOOS=linux make build-server

#################
### UI Build Step
#################
FROM node:14-buster AS ui-builder

RUN mkdir /ui
WORKDIR /ui

COPY . .
Expand All @@ -32,7 +34,6 @@ FROM 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 All @@ -49,4 +50,4 @@ EXPOSE 3000

HEALTHCHECK --timeout=5s CMD ./fider ping

CMD ./fider migrate && ./fider
CMD ./fider migrate && ./fider
30 changes: 13 additions & 17 deletions app/pkg/dbx/migrate.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"io/ioutil"
"os"
"sort"
"strconv"
"strings"

"github.com/getfider/fider/app/models/dto"
Expand All @@ -32,22 +31,19 @@ func Migrate(ctx context.Context, path string) error {
return errors.Wrap(err, "failed to read files from dir '%s'", path)
}

versions := make([]int, len(files))
versionFiles := make(map[int]string, len(files))
versions := make([]string, len(files))
versionFiles := make(map[string]string, len(files))
for i, file := range files {
fileName := file.Name()
parts := strings.Split(fileName, "_")
if len(parts[0]) != 12 {
return errors.New("migration file must have exactly 12 chars for version: '%s' is invalid.", fileName)
}

versions[i], err = strconv.Atoi(parts[0])
versions[i] = parts[0]
versionFiles[versions[i]] = fileName
if err != nil {
return errors.Wrap(err, "failed to convert '%s' to number", parts[0])
}
}
sort.Ints(versions)
sort.Strings(versions)

log.Infof(ctx, "Found total of @{Total} migration files.", dto.Props{
"Total": len(versions),
Expand Down Expand Up @@ -90,7 +86,7 @@ func Migrate(ctx context.Context, path string) error {
return nil
}

func runMigration(ctx context.Context, version int, path, fileName string) error {
func runMigration(ctx context.Context, version, path, fileName string) error {
filePath := env.Path(path + "/" + fileName)
content, err := ioutil.ReadFile(filePath)
if err != nil {
Expand All @@ -115,29 +111,29 @@ func runMigration(ctx context.Context, version int, path, fileName string) error
return trx.Commit()
}

func getLastMigration() (int, error) {
func getLastMigration() (string, error) {
_, err := conn.Exec(`CREATE TABLE IF NOT EXISTS migrations_history (
version BIGINT PRIMARY KEY,
filename VARCHAR(100) null,
date TIMESTAMPTZ NOT NULL DEFAULT NOW()
date TIMESTAMPTZ NOT NULL DEFAULT NOW()
)`)
if err != nil {
return 0, err
return "", err
}

var lastVersion sql.NullInt64
row := conn.QueryRow("SELECT MAX(version) FROM migrations_history LIMIT 1")
var lastVersion sql.NullString
row := conn.QueryRow("SELECT CAST(MAX(version) as varchar) FROM migrations_history LIMIT 1")
err = row.Scan(&lastVersion)
if err != nil {
return 0, err
return "", err
}

if !lastVersion.Valid {
// If it's the first run, maybe we have records on old migrations table, so try to get from it.
// This SHOULD be removed in the far future.
row := conn.QueryRow("SELECT version FROM schema_migrations LIMIT 1")
row := conn.QueryRow("SELECT CAST(version as varchar) FROM schema_migrations LIMIT 1")
_ = row.Scan(&lastVersion)
}

return int(lastVersion.Int64), nil
return lastVersion.String, nil
}

0 comments on commit 64fbcd2

Please sign in to comment.