Skip to content

Commit

Permalink
Add various updates
Browse files Browse the repository at this point in the history
- Migrate to ghcr.io container registry
- Publish images labels with full version
- Use non-root image in Docker image
- Use embed instead of packr to embed assets
- Update Go to 1.21 and module deps
- Drop API schema publishing functionality
  • Loading branch information
sevein committed Oct 1, 2023
1 parent cdaf1b8 commit 96f34d6
Show file tree
Hide file tree
Showing 34 changed files with 189 additions and 747 deletions.
34 changes: 22 additions & 12 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,32 +1,42 @@
name: GoReleaser
on:
push:
tags:
- 'v*'
name: GoReleaser
permissions:
contents: write
packages: write
jobs:
release:
name: Release
runs-on: ubuntu-latest
steps:
- name: Check out code
uses: actions/checkout@v2
uses: actions/checkout@v4
with:
show-progress: false
fetch-depth: 0
- name: Fetch all tags
run: git fetch origin +refs/tags/*:refs/tags/*
- name: Install Go
uses: actions/setup-go@v1
uses: actions/setup-go@v4
with:
go-version-file: go.mod
- name: Log in to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Log in to the GitHub Container Registry
uses: docker/login-action@v3
with:
go-version: 1.15.x
- name: Install Docker credentials
run: |
docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }}
docker login -u qubot -p ${{ secrets.GITHUB_TOKEN }} docker.pkg.github.com
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v1
uses: goreleaser/goreleaser-action@v5
with:
distribution: goreleaser
version: latest
args: release
env:
GITHUB_TOKEN: ${{ secrets.QUBOT_GITHUB_TOKEN }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
if: success()
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,4 @@
/web/node_modules

*.swp
*-packr.go
*.log
26 changes: 18 additions & 8 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ project_name: amflow
before:
hooks:
- make clean
- make deps
- make prebuild
- make frontend

builds:
- ldflags:
Expand All @@ -24,13 +23,24 @@ checksum:
dockers:
- goos: linux
goarch: amd64
dockerfile: Dockerfile.release
image_templates:
- "artefactual/amflow:latest"
- "artefactual/amflow:v{{ .Major }}"
- "docker.pkg.github.com/artefactual-labs/amflow/amflow:latest"
- "docker.pkg.github.com/artefactual-labs/amflow/amflow:v{{ .Major }}"
dockerfile: Dockerfile.release
- "artefactual/amflow:{{ .Tag }}"
- "ghcr.io/artefactual-labs/amflow/amflow:latest"
- "ghcr.io/artefactual-labs/amflow/amflow:v{{ .Major }}"
- "ghcr.io/artefactual-labs/amflow/amflow:{{ .Tag }}"
build_flag_templates:
- "--label=org.label-schema.schema-version=1.0"
- "--label=org.label-schema.version={{.Version}}"
- "--label=org.label-schema.name={{.ProjectName}}"
- "--pull"
- "--platform=linux/amd64"
- "--label=org.opencontainers.image.title={{.ProjectName}}"
- "--label=org.opencontainers.image.vendor=Artefactual Systems Inc."
- "--label=org.opencontainers.image.description=amflow {{.Tag}}"
- "--label=org.opencontainers.image.url=https://github.com/artefactual-labs/amflow"
- "--label=org.opencontainers.image.documentation=https://github.com/artefactual-labs/amflow/blob/main/README.md"
- "--label=org.opencontainers.image.source=https://github.com/artefactual-labs/amflow"
- "--label=org.opencontainers.image.licenses=Apache-2.0"
- "--label=org.opencontainers.image.version={{.Version}}"
- "--label=org.opencontainers.image.revision={{.FullCommit}}"
- "--label=org.opencontainers.image.created={{.Date}}"
4 changes: 1 addition & 3 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
"dist": true,
"public/assets": true,
"web/.cache": true,
"web/node_modules": true,
"packrd": true,
"**/*-packr.go": true
"web/node_modules": true
}
}
10 changes: 4 additions & 6 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
FROM node:11 as frontend
FROM node:18 as frontend
WORKDIR /src
COPY ./ui ./ui
RUN yarn --cwd /src/ui install
RUN yarn --cwd /src/ui build

ARG GO_VERSION=1.15
FROM golang:${GO_VERSION}-alpine AS build
FROM golang:1.21.1-alpine AS build
RUN apk add --no-cache ca-certificates git make
WORKDIR /src
COPY ./go.mod ./go.sum ./Makefile ./
RUN make deps
COPY ./ ./
RUN make build

FROM alpine:3.11 AS final
FROM alpine:3.18 AS final
RUN apk --no-cache add ca-certificates graphviz
COPY --from=build /tmp/amflow /bin/amflow
COPY --from=build /src/dist/amflow /bin/amflow
ENTRYPOINT ["/amflow"]
5 changes: 4 additions & 1 deletion Dockerfile.release
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# This is used by GoReleaser.
FROM alpine:3.11 AS final
FROM alpine:3.18 AS final
RUN apk --no-cache add ca-certificates graphviz
COPY amflow /
RUN addgroup -S amflow
RUN adduser -S amflow -G amflow
USER amflow
ENTRYPOINT ["/amflow"]
14 changes: 1 addition & 13 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@ help:
@echo " check check all the things"
@echo " help this help message"

tools:
env GO111MODULE=off go get github.com/gobuffalo/packr/packr2

.PHONY: deps
deps: tools
@echo "Downloading modules..."
Expand All @@ -27,29 +24,20 @@ deps: tools
.PHONY: goagen
goagen:
@goagen app -d github.com/artefactual-labs/amflow/design -o internal/api
@goagen swagger -d github.com/artefactual-labs/amflow/design -o public
@goagen schema -d github.com/artefactual-labs/amflow/design -o public
@goagen js -d github.com/artefactual-labs/amflow/design -o web/js/client --noexample

.PHONY: clean
clean:
git clean -f -d -x

.PHONY: prebuild
prebuild: frontend generate

.PHONY: build
build: prebuild
build:
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 GOFLAGS=-ldflags=-w \
go build \
-o dist/amflow \
-ldflags="-s -X github.com/artefactual-labs/amflow/internal/version.version=try" \
github.com/artefactual-labs/amflow

.PHONY: generate
generate:
go generate

.PHONY: frontend
frontend:
yarn --cwd web install
Expand Down
15 changes: 7 additions & 8 deletions cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ package cmd
import (
"fmt"
"io"
"io/ioutil"
"net/http"
"net/url"
"os"
Expand All @@ -17,14 +16,14 @@ import (
"github.com/spf13/cobra"
"go.uber.org/multierr"

"github.com/artefactual-labs/amflow/internal/constants"
"github.com/artefactual-labs/amflow/internal/graph"
"github.com/artefactual-labs/amflow/internal/graph/encoding"
"github.com/artefactual-labs/amflow/internal/version"
)

var (
v string
v string
defaultLogLevel = logrus.InfoLevel
)

var rootCmd = &cobra.Command{
Expand All @@ -43,7 +42,7 @@ func command(out, err io.Writer) *cobra.Command {
return err
}
rootCmd.SilenceUsage = true
logrus.Infof("amflow %+s", version.Get())
logrus.Infof("amflow %+s", version.Version())
return nil
}

Expand All @@ -54,7 +53,7 @@ func command(out, err io.Writer) *cobra.Command {
rootCmd.AddCommand(newCmdSearch(out))
rootCmd.AddCommand(newCmdCheck(out))

rootCmd.PersistentFlags().StringVarP(&v, "verbosity", "v", constants.DefaultLogLevel.String(), "Log level (debug, info, warn, error, fatal, panic")
rootCmd.PersistentFlags().StringVarP(&v, "verbosity", "v", defaultLogLevel.String(), "Log level (debug, info, warn, error, fatal, panic")

return rootCmd
}
Expand All @@ -79,13 +78,13 @@ func load(file string) (*graph.Workflow, error) {
// Load workflow bytes.
if file == "" {
logrus.WithFields(logrus.Fields{"mode": "embedded"}).Info("Loading workfow")
bytes, err = graph.WorkflowSchemaBox.Find("example.json")
bytes = graph.WorkflowSample
} else if isURL(file) {
logrus.WithFields(logrus.Fields{"mode": "file", "source": file}).Info("Downloading workfow")
bytes, err = downloadRemote(file)
} else {
logrus.WithFields(logrus.Fields{"mode": "file", "source": file}).Info("Loading workfow")
bytes, err = ioutil.ReadFile(file)
bytes, err = os.ReadFile(file)
}
if err != nil {
return nil, errors.WithMessage(err, "Workflow could not be retrieved")
Expand Down Expand Up @@ -134,7 +133,7 @@ func downloadRemote(addr string) ([]byte, error) {
return nil, fmt.Errorf("remote server returned and unexpected response with status code: %d", resp.StatusCode)
}
defer resp.Body.Close()
bytes, err := ioutil.ReadAll(resp.Body)
bytes, err := io.ReadAll(resp.Body)
if err != nil {
return nil, errors.WithMessage(err, "remote resource could not be loaded")
}
Expand Down
1 change: 1 addition & 0 deletions cmd/edit.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ func edit(out io.Writer) error {
}
defer ln.Close()
logger := logrus.WithField("subsystem", "api")
logger.WithField("port", ln.Addr()).Info("Staring API server")
svc := api.Create(w, logger)
if err := svc.Serve(ln); err != nil {
svc.LogError("startup", "err", err)
Expand Down
2 changes: 1 addition & 1 deletion cmd/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ func newCmdVersion(out io.Writer) *cobra.Command {
Use: "version",
Short: "Print the version information",
RunE: func(cmd *cobra.Command, args []string) error {
fmt.Println(version.Get())
fmt.Println(version.Version())
return nil
},
}
Expand Down
10 changes: 1 addition & 9 deletions design/resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,17 +55,9 @@ var _ = Resource("workflow", func() {
})
})

var _ = Resource("swagger", func() {
Files("/swagger/*filepath", "public/swagger/")
})

var _ = Resource("schema", func() {
Files("/schema/*filepath", "public/schema/")
})

var _ = Resource("web", func() {
Origin("*", func() {
Methods("GET, OPTIONS")
})
Files("/*filepath", "public/web/")
Files("/*filepath", "web/")
})
43 changes: 24 additions & 19 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,34 +1,39 @@
module github.com/artefactual-labs/amflow

go 1.15
go 1.21

require (
github.com/goadesign/goa v1.4.3
github.com/olekukonko/tablewriter v0.0.5
github.com/pkg/errors v0.9.1
github.com/sirupsen/logrus v1.9.3
github.com/spf13/cobra v1.7.0
github.com/stretchr/testify v1.8.4
go.uber.org/multierr v1.11.0
gonum.org/v1/gonum v0.14.0
)

require (
github.com/armon/go-metrics v0.0.0-20180917152333-f0300d1749da // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/dimfeld/httppath v0.0.0-20170720192232-ee938bf73598 // indirect
github.com/dimfeld/httptreemux v5.0.1+incompatible // indirect
github.com/goadesign/goa v1.0.1-0.20181221201017-4a2fb392efda
github.com/gobuffalo/packr/v2 v2.7.1
github.com/gofrs/uuid v4.4.0+incompatible // indirect
github.com/google/gxui v0.0.0-20151028112939-f85e0a97b3a4 // indirect
github.com/gopherjs/gopherjs v0.0.0-20181103185306-d547d1d9531e // indirect
github.com/hashicorp/go-immutable-radix v1.0.0 // indirect
github.com/hashicorp/go-uuid v1.0.1 // indirect
github.com/jtolds/gls v4.2.1+incompatible // indirect
github.com/hashicorp/golang-lru v0.5.1 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/manveru/faker v0.0.0-20171103152722-9fbc68a78c4d // indirect
github.com/manveru/gobdd v0.0.0-20131210092515-f1a17fdd710b // indirect
github.com/olekukonko/tablewriter v0.0.4
github.com/mattn/go-runewidth v0.0.9 // indirect
github.com/onsi/ginkgo v1.7.0 // indirect
github.com/onsi/gomega v1.4.3 // indirect
github.com/pascaldekloe/goe v0.0.0-20180627143212-57f6aae5913c // indirect
github.com/pkg/errors v0.9.1
github.com/satori/go.uuid v1.2.1-0.20181028125025-b2ce2384e17b // indirect
github.com/sirupsen/logrus v1.4.2
github.com/smartystreets/assertions v0.0.0-20190116191733-b6c0e53d7304 // indirect
github.com/smartystreets/goconvey v0.0.0-20181108003508-044398e4856c // indirect
github.com/spf13/cobra v0.0.6
github.com/stretchr/testify v1.5.1
github.com/pascaldekloe/goe v0.1.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/smartystreets/goconvey v1.8.1 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/zach-klippenstein/goregen v0.0.0-20160303162051-795b5e3961ea // indirect
go.uber.org/multierr v1.5.0
golang.org/x/exp v0.0.0-20190316020145-860388717186 // indirect
gonum.org/v1/gonum v0.7.0
gonum.org/v1/netlib v0.0.0-20190314102120-fc220b4194ca // indirect
golang.org/x/net v0.8.0 // indirect
golang.org/x/sys v0.6.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)

0 comments on commit 96f34d6

Please sign in to comment.