Skip to content

Commit 77687d4

Browse files
authored
Merge pull request #455 from kindlyops/oci-image
build and publish container image to ghcr.io during release
2 parents cdd4cea + 675020e commit 77687d4

7 files changed

Lines changed: 158 additions & 7 deletions

File tree

.github/workflows/release-publisher.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,14 @@ jobs:
3333
run: |
3434
curl -sSfL https://raw.githubusercontent.com/anchore/syft/main/install.sh | \
3535
sh -s -- -b /usr/local/bin v0.32.0
36+
- name: Login to GitHub Container Registry
37+
uses: docker/login-action@v1
38+
with:
39+
registry: ghcr.io
40+
username: ${{ github.actor }}
41+
password: ${{ secrets.GITHUB_TOKEN }}
42+
- name: Push vbs image to ghcr.io
43+
run: bazel run --define=IMAGE_TAG=${{ github.ref_name }} --stamp //:push_image
3644
- name: Run goreleaser
3745
uses: goreleaser/goreleaser-action@master
3846
env:

.golangci.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,25 @@ linters:
4242
- ifshort
4343
- gofumpt
4444
- tagliatelle
45+
- structcheck
46+
- staticcheck
47+
- unparam
48+
- wastedassign
49+
- noctx
50+
- nilerr
51+
- bodyclose
52+
- contextcheck
53+
- stylecheck
54+
- gosimple
55+
- golint
56+
- sqlclosecheck
57+
- rowserrcheck
58+
- tparallel
59+
- unused
4560

4661
run:
62+
skip-dirs:
63+
- vendor
64+
- external
4765
skip-files:
4866
- dummy.go

BUILD.bazel

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_library", "go_test")
22
load("@bazel_gazelle//:def.bzl", "gazelle")
33
load("//:version.bzl", "VERSION")
44
load("@bazel_skylib//rules:copy_file.bzl", "copy_file")
5+
load("@io_bazel_rules_docker//go:image.bzl", "go_image")
6+
load("@io_bazel_rules_docker//container:container.bzl", "container_image", "container_push")
57

68
package(default_visibility = ["//visibility:public"])
79

@@ -76,6 +78,40 @@ go_binary(
7678
},
7779
)
7880

81+
DEFAULT_BASE = select({
82+
"@io_bazel_rules_docker//:debug": "@go_debug_image_base//image",
83+
"@io_bazel_rules_docker//:fastbuild": "@go_image_base//image",
84+
"@io_bazel_rules_docker//:optimized": "@go_image_base//image",
85+
"//conditions:default": "@go_image_base//image",
86+
})
87+
88+
# using container_image since go_image is not forwarding
89+
# the labels to the underlying container_image
90+
container_image(
91+
name = "vbs_base",
92+
base = DEFAULT_BASE,
93+
labels = {
94+
"org.opencontainers.image.source" : "https://github.com/kindlyops/vbs",
95+
},
96+
)
97+
98+
# see https://github.com/bazelbuild/rules_docker/pull/2087 for pending multi-arch
99+
go_image(
100+
base = ":vbs_base",
101+
name = "vbs_image",
102+
binary = ":vbs-linux",
103+
)
104+
105+
container_push(
106+
name = "push_image",
107+
format = "Docker",
108+
image = ":vbs_image",
109+
registry = "ghcr.io",
110+
repository = "kindlyops/vbs",
111+
tag = "$(IMAGE_TAG)",
112+
tags=["manual"],
113+
)
114+
79115
alias(
80116
name = "vbs",
81117
actual = select({

README.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,3 +70,20 @@ Want to help add features or fix bugs? Awesome! vbs is build using bazel.
7070
To run goreleaser locally to test changes to the release process configuration:
7171

7272
goreleaser release --snapshot --skip-publish --rm-dist
73+
74+
### Running container image locally
75+
76+
To run the container image locally to test changes to the container:
77+
78+
bazel run vbs_image -- --publish=8090:8090 -- serve
79+
80+
To inspect the contents of the container using the dive utility
81+
82+
bazel run vbs_image -- --norun
83+
dive bazel:vbs_image
84+
85+
### pushing an experimental version of the image to github container registry
86+
87+
To push a locally built image to github container registry:
88+
89+
bazel run --define=IMAGE_TAG=experimental --stamp //:push_image

WORKSPACE

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,3 +84,78 @@ yarn_install(
8484
quiet = False,
8585
yarn_lock = "//embeddy:yarn.lock",
8686
)
87+
88+
http_archive(
89+
name = "io_bazel_rules_docker",
90+
sha256 = "b1e80761a8a8243d03ebca8845e9cc1ba6c82ce7c5179ce2b295cd36f7e394bf",
91+
urls = ["https://github.com/bazelbuild/rules_docker/releases/download/v0.25.0/rules_docker-v0.25.0.tar.gz"],
92+
)
93+
94+
# OPTIONAL: Call this to override the default docker toolchain configuration.
95+
# This call should be placed BEFORE the call to "container_repositories" below
96+
# to actually override the default toolchain configuration.
97+
# Note this is only required if you actually want to call
98+
# docker_toolchain_configure with a custom attr; please read the toolchains
99+
# docs in /toolchains/docker/ before blindly adding this to your WORKSPACE.
100+
# BEGIN OPTIONAL segment:
101+
load("@io_bazel_rules_docker//toolchains/docker:toolchain.bzl",
102+
docker_toolchain_configure="toolchain_configure"
103+
)
104+
# docker_toolchain_configure(
105+
# name = "docker_config",
106+
# # OPTIONAL: Bazel target for the build_tar tool, must be compatible with build_tar.py
107+
# build_tar_target="<enter absolute path (i.e., must start with repo name @...//:...) to an executable build_tar target>",
108+
# # OPTIONAL: Path to a directory which has a custom docker client config.json.
109+
# # See https://docs.docker.com/engine/reference/commandline/cli/#configuration-files
110+
# # for more details.
111+
# client_config="<enter Bazel label to your docker config.json here>",
112+
# # OPTIONAL: Path to the docker binary.
113+
# # Should be set explicitly for remote execution.
114+
# docker_path="<enter absolute path to the docker binary (in the remote exec env) here>",
115+
# # OPTIONAL: Path to the gzip binary.
116+
# gzip_path="<enter absolute path to the gzip binary (in the remote exec env) here>",
117+
# # OPTIONAL: Bazel target for the gzip tool.
118+
# gzip_target="<enter absolute path (i.e., must start with repo name @...//:...) to an executable gzip target>",
119+
# # OPTIONAL: Path to the xz binary.
120+
# # Should be set explicitly for remote execution.
121+
# xz_path="<enter absolute path to the xz binary (in the remote exec env) here>",
122+
# # OPTIONAL: Bazel target for the xz tool.
123+
# # Either xz_path or xz_target should be set explicitly for remote execution.
124+
# xz_target="<enter absolute path (i.e., must start with repo name @...//:...) to an executable xz target>",
125+
# # OPTIONAL: List of additional flags to pass to the docker command.
126+
# docker_flags = [
127+
# "--tls",
128+
# "--log-level=info",
129+
# ],
130+
131+
# )
132+
# End of OPTIONAL segment.
133+
134+
load(
135+
"@io_bazel_rules_docker//repositories:repositories.bzl",
136+
container_repositories = "repositories",
137+
)
138+
container_repositories()
139+
140+
load("@io_bazel_rules_docker//repositories:deps.bzl", container_deps = "deps")
141+
142+
container_deps()
143+
144+
load(
145+
"@io_bazel_rules_docker//container:container.bzl",
146+
"container_pull",
147+
)
148+
load(
149+
"@io_bazel_rules_docker//go:image.bzl",
150+
_go_image_repos = "repositories",
151+
)
152+
153+
_go_image_repos()
154+
155+
container_pull(
156+
name = "static_base",
157+
registry = "gcr.io",
158+
repository = "distroless/static",
159+
# 'tag' is also supported, but digest is encouraged for reproducibility.
160+
digest = "sha256:d1d4a57d06e3c59f71cd1d72d894ab2a3c17973684d42348fbe84c1396fb4b41",
161+
)

cmd/fly.go

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import (
2121
"github.com/muesli/coral"
2222
"github.com/pocketbase/pocketbase"
2323
"github.com/rs/zerolog/log"
24-
"github.com/spf13/viper"
2524
)
2625

2726
var flyServerCmd = &coral.Command{
@@ -33,8 +32,6 @@ var flyServerCmd = &coral.Command{
3332
}
3433

3534
func flyServer(cmd *coral.Command, args []string) {
36-
_ = "127.0.0.1:" + viper.GetString("port")
37-
3835
configDir, err := os.UserConfigDir()
3936
if err != nil {
4037
log.Fatal().Stack().Err(err).Msg("Couldn't locate config dir")
@@ -65,10 +62,10 @@ func flyServer(cmd *coral.Command, args []string) {
6562
}
6663

6764
// Port to listen for HTTP requests.
68-
var FlyPort string
65+
var httpTarget string
6966

7067
func init() {
71-
flyServerCmd.Flags().StringVarP(&FlyPort, "port", "p", "8080", "Port to listen for HTTP requests")
72-
viper.BindPFlag("port", flyServerCmd.Flags().Lookup("port"))
68+
flyServerCmd.Flags().StringVarP(&httpTarget, "http", "a", "0.0.0.0:8090", "Address & port to listen for HTTP requests")
69+
//viper.BindPFlag("port", flyServerCmd.Flags().Lookup("port"))
7370
rootCmd.AddCommand(flyServerCmd)
7471
}

cmd/root.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import (
2020
"path/filepath"
2121
"time"
2222

23-
"github.com/mattn/go-isatty"
23+
isatty "github.com/mattn/go-isatty"
2424
"github.com/muesli/coral"
2525
"github.com/rs/zerolog"
2626
"github.com/rs/zerolog/log"

0 commit comments

Comments
 (0)