diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 4e42d6b68..02073c852 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -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 }} diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml deleted file mode 100644 index 1ce9a222b..000000000 --- a/.github/workflows/publish.yml +++ /dev/null @@ -1,59 +0,0 @@ -name: publish - -on: - workflow_run: - workflows: ["build"] - types: - - completed - -jobs: - publish: - runs-on: ubuntu-latest - if: ${{ github.event.workflow_run.conclusion == 'success' }} - steps: - - name: log origin event - env: - ORIGIN: ${{ github.event.html_url }} - run: echo "$ORIGIN" - - name: download artifact - uses: actions/github-script@v3.1.0 - 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 == "out" - })[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}}/out.zip', Buffer.from(download.data)); - - run: unzip out.zip - - run: docker load --input fider.tar - - - 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) - if: ${{ github.event.workflow_run.event == 'pull_request' }} - run: | - docker tag getfider/fider getfider/fider:PR_$(cat ./pr) - docker push getfider/fider:PR_$(cat ./pr) - - - name: push docker image (push) - if: ${{ github.event.workflow_run.event == 'push' }} - run: | - docker tag getfider/fider getfider/fider:SHA_$(cat ./sha7) - docker push getfider/fider:SHA_$(cat ./sha7) - docker tag getfider/fider getfider/fider:main - docker push getfider/fider:main diff --git a/Dockerfile b/Dockerfile index 9dc0114ba..34a0eccc5 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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 . . @@ -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 @@ -49,4 +50,4 @@ EXPOSE 3000 HEALTHCHECK --timeout=5s CMD ./fider ping -CMD ./fider migrate && ./fider \ No newline at end of file +CMD ./fider migrate && ./fider diff --git a/app/pkg/dbx/migrate.go b/app/pkg/dbx/migrate.go index bfd04cea2..e137a01d4 100644 --- a/app/pkg/dbx/migrate.go +++ b/app/pkg/dbx/migrate.go @@ -7,7 +7,6 @@ import ( "io/ioutil" "os" "sort" - "strconv" "strings" "github.com/getfider/fider/app/models/dto" @@ -32,8 +31,8 @@ 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, "_") @@ -41,13 +40,10 @@ func Migrate(ctx context.Context, path string) error { 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), @@ -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 { @@ -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 }