Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: create multiarch docker image #874

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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/amd64,linux/arm/v7
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.

12 changes: 5 additions & 7 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,19 @@
#####################
FROM golang:1.16.2-buster AS server-builder

ARG buildnumber=local
ARG BUILDNUMBER=local
ARG TARGETVARIANT

RUN mkdir /server
WORKDIR /server

COPY . .
RUN BUILDNUMBER=${buildnumber} GOOS=linux GOARCH=amd64 make build-server
RUN GOARM=$(echo "$TARGETVARIANT" | tail -c 2) make build-server

#################
### UI Build Step
#################
FROM node:14-buster AS ui-builder
FROM --platform=linux/amd64 node:14-buster AS ui-builder

RUN mkdir /ui
WORKDIR /ui

COPY . .
Expand All @@ -32,7 +31,6 @@ FROM debian:buster-slim
RUN apt-get update
RUN apt-get install -y ca-certificates

RUN mkdir /app
goenning marked this conversation as resolved.
Show resolved Hide resolved
WORKDIR /app

COPY --from=server-builder /server/migrations /app/migrations
Expand All @@ -49,4 +47,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
}