Skip to content

Commit f6c6cd2

Browse files
author
Jordan Halterman
committed
Add runtime image build
1 parent a28cf19 commit f6c6cd2

15 files changed

Lines changed: 972 additions & 16 deletions

File tree

.github/workflows/build.yml

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,12 @@ jobs:
1414
uses: actions/checkout@v2
1515
with:
1616
fetch-depth: 0
17-
- name: Set up Go
18-
uses: actions/setup-go@v2
17+
- name: Docker Login
18+
uses: docker/login-action@v1
1919
with:
20-
go-version: 1.18
21-
- name: Cache Go modules
22-
uses: actions/cache@v1
23-
with:
24-
path: ~/go/pkg/mod
25-
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
26-
restore-keys: |
27-
${{ runner.os }}-go-
28-
- name: Tests
29-
run: |
30-
go mod tidy
31-
go test -v ./...
20+
username: ${{ secrets.DOCKER_USERNAME }}
21+
password: ${{ secrets.DOCKER_PASSWORD }}
22+
- name: Build
23+
run: make build
24+
env:
25+
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}

.github/workflows/release.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
name: release
2+
3+
on:
4+
push:
5+
tags:
6+
- 'v*'
7+
pull_request:
8+
9+
jobs:
10+
release:
11+
runs-on: ubuntu-20.04
12+
steps:
13+
- name: Checkout
14+
uses: actions/checkout@v2
15+
with:
16+
fetch-depth: 0
17+
- name: Docker Login
18+
uses: docker/login-action@v1
19+
with:
20+
username: ${{ secrets.DOCKER_USERNAME }}
21+
password: ${{ secrets.DOCKER_PASSWORD }}
22+
- name: Setup Release Environment
23+
run: |-
24+
echo 'GITHUB_TOKEN=${{secrets.GH_TOKEN}}' > .release-env
25+
- name: Release
26+
run: make release
27+
env:
28+
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}

Makefile

Lines changed: 49 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,55 @@
22
#
33
# SPDX-License-Identifier: Apache-2.0
44

5-
build:
6-
go build ./...
5+
GOLANG_CROSS_VERSION := v1.18.2-v1.8.3
6+
7+
build: build-bin build-docker
8+
9+
build-bin:
10+
docker run \
11+
--rm \
12+
--privileged \
13+
-e CGO_ENABLED=1 \
14+
-v /var/run/docker.sock:/var/run/docker.sock \
15+
-v `pwd`:/build \
16+
-w /build \
17+
goreleaser/goreleaser-cross:${GOLANG_CROSS_VERSION} \
18+
release -f ./build/bin.yaml --snapshot --rm-dist
19+
20+
build-docker:
21+
docker run \
22+
--rm \
23+
--privileged \
24+
-e CGO_ENABLED=1 \
25+
-v /var/run/docker.sock:/var/run/docker.sock \
26+
-v `pwd`:/build \
27+
-w /build \
28+
goreleaser/goreleaser-cross:${GOLANG_CROSS_VERSION} \
29+
release -f ./build/docker.yaml --snapshot --rm-dist
30+
31+
release: release-bin release-docker
32+
33+
release-bin:
34+
docker run \
35+
--rm \
36+
--privileged \
37+
-e CGO_ENABLED=1 \
38+
-v /var/run/docker.sock:/var/run/docker.sock \
39+
-v `pwd`:/build \
40+
-w /build \
41+
goreleaser/goreleaser-cross:${GOLANG_CROSS_VERSION} \
42+
release -f ./build/bin.yaml --rm-dist
43+
44+
release-docker:
45+
docker run \
46+
--rm \
47+
--privileged \
48+
-e CGO_ENABLED=1 \
49+
-v /var/run/docker.sock:/var/run/docker.sock \
50+
-v `pwd`:/build \
51+
-w /build \
52+
goreleaser/goreleaser-cross:${GOLANG_CROSS_VERSION} \
53+
release -f ./build/docker.yaml --rm-dist
754

855
api: go docs
956

build/Dockerfile

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# SPDX-FileCopyrightText: 2022-present Intel Corporation
2+
#
3+
# SPDX-License-Identifier: Apache-2.0
4+
5+
FROM alpine:3.15
6+
7+
RUN apk add libc6-compat
8+
9+
RUN addgroup -S atomix && adduser -S -G atomix atomix
10+
11+
USER atomix
12+
13+
COPY dist/bin/atomix-runtime_linux_amd64_v1/atomix-runtime /usr/local/bin/atomix-runtime
14+
15+
ENTRYPOINT ["atomix-runtime"]

build/bin.yaml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# SPDX-FileCopyrightText: 2022-present Intel Corporation
2+
#
3+
# SPDX-License-Identifier: Apache-2.0
4+
5+
project_name: atomix-runtime-bin
6+
7+
dist: dist/bin
8+
9+
before:
10+
hooks:
11+
- go mod tidy
12+
13+
builds:
14+
- id: atomix-runtime
15+
main: ./cmd/atomix-runtime
16+
binary: atomix-runtime
17+
goos:
18+
- linux
19+
goarch:
20+
- amd64
21+
env:
22+
- CC=gcc
23+
- CXX=g++
24+
flags:
25+
- -mod=readonly
26+
- -trimpath
27+
gcflags:
28+
- all=-N -l
29+
ldflags:
30+
- -s -w
31+
- -X github.com/atomix/runtime/version.version={{ .Version }}

build/docker.yaml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# SPDX-FileCopyrightText: 2022-present Intel Corporation
2+
#
3+
# SPDX-License-Identifier: Apache-2.0
4+
5+
project_name: atomix-runtime-docker
6+
7+
dist: dist/docker
8+
9+
before:
10+
hooks:
11+
- go mod tidy
12+
13+
builds:
14+
- skip: true
15+
16+
dockers:
17+
- id: atomix-runtime
18+
dockerfile: ./build/Dockerfile
19+
image_templates:
20+
- "atomix/runtime:latest"
21+
- "{{ if (not .IsSnapshot) }}atomix/runtime:{{ .Tag }}{{ end }}"
22+
- "{{ if (not .IsSnapshot) }}atomix/runtime:v{{ .Major }}.{{ .Minor }}{{ end }}"
23+
extra_files:
24+
- dist/bin/atomix-runtime_linux_amd64_v1/atomix-runtime
25+
26+
checksum:
27+
name_template: 'checksums.txt'
28+
29+
snapshot:
30+
name_template: "{{ incpatch .Version }}-{{.ShortCommit}}"

cmd/atomix-runtime/main.go

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
// SPDX-FileCopyrightText: 2022-present Intel Corporation
2+
//
3+
// SPDX-License-Identifier: Apache-2.0
4+
5+
package main
6+
7+
import (
8+
"fmt"
9+
"github.com/atomix/runtime/pkg/runtime"
10+
"github.com/spf13/cobra"
11+
"os"
12+
"os/signal"
13+
"syscall"
14+
)
15+
16+
func main() {
17+
cmd := &cobra.Command{
18+
Use: "atomix-runtime",
19+
Run: func(cmd *cobra.Command, args []string) {
20+
proxyHost, err := cmd.Flags().GetString("proxy-host")
21+
if err != nil {
22+
fmt.Fprintln(cmd.OutOrStderr(), err.Error())
23+
os.Exit(1)
24+
}
25+
proxyPort, err := cmd.Flags().GetInt("proxy-port")
26+
if err != nil {
27+
fmt.Fprintln(cmd.OutOrStderr(), err.Error())
28+
os.Exit(1)
29+
}
30+
runtimeHost, err := cmd.Flags().GetString("runtime-host")
31+
if err != nil {
32+
fmt.Fprintln(cmd.OutOrStderr(), err.Error())
33+
os.Exit(1)
34+
}
35+
runtimePort, err := cmd.Flags().GetInt("runtime-port")
36+
if err != nil {
37+
fmt.Fprintln(cmd.OutOrStderr(), err.Error())
38+
os.Exit(1)
39+
}
40+
configFile, err := cmd.Flags().GetString("config")
41+
if err != nil {
42+
fmt.Fprintln(cmd.OutOrStderr(), err.Error())
43+
os.Exit(1)
44+
}
45+
cacheDir, err := cmd.Flags().GetString("cache")
46+
if err != nil {
47+
fmt.Fprintln(cmd.OutOrStderr(), err.Error())
48+
os.Exit(1)
49+
}
50+
51+
rt := runtime.New(
52+
runtime.WithProxyHost(proxyHost),
53+
runtime.WithProxyPort(proxyPort),
54+
runtime.WithRuntimeHost(runtimeHost),
55+
runtime.WithRuntimePort(runtimePort),
56+
runtime.WithConfigFile(configFile),
57+
runtime.WithCacheDir(cacheDir))
58+
if err := rt.Start(); err != nil {
59+
fmt.Fprintln(cmd.OutOrStderr(), err.Error())
60+
os.Exit(1)
61+
}
62+
63+
// Wait for an interrupt signal
64+
ch := make(chan os.Signal, 2)
65+
signal.Notify(ch, os.Interrupt, syscall.SIGTERM)
66+
<-ch
67+
68+
// Stop the proxy service
69+
if err := rt.Stop(); err != nil {
70+
fmt.Println(err)
71+
os.Exit(1)
72+
}
73+
},
74+
}
75+
cmd.Flags().StringP("proxy-host", "h", "", "the host to which to bind the proxy server")
76+
cmd.Flags().IntP("proxy-port", "p", 5678, "the port to which to bind the proxy server")
77+
cmd.Flags().String("runtime-host", "", "the host to which to bind the runtime server")
78+
cmd.Flags().Int("runtime-port", 5679, "the port to which to bind the runtime server")
79+
cmd.Flags().StringP("config", "c", "~/.atomix/config.yaml", "the path to the Atomix configuration file")
80+
cmd.Flags().String("cache", "~/.atomix/cache", "the path to the Atomix cache")
81+
82+
if err := cmd.Execute(); err != nil {
83+
panic(err)
84+
}
85+
}

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ go 1.18
44

55
require (
66
github.com/cenkalti/backoff v2.2.1+incompatible
7+
github.com/gofrs/flock v0.8.1
78
github.com/gogo/protobuf v1.3.2
89
github.com/golang/protobuf v1.5.2
910
github.com/mitchellh/go-homedir v1.1.0

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeME
7575
github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU=
7676
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20191125211704-12ad95a8df72/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8=
7777
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20200222043503-6f7a984d4dc4/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8=
78+
github.com/gofrs/flock v0.8.1 h1:+gYjHKf32LDeiEEFhQaotPbLuUXjY5ZqxKgXy7n59aw=
79+
github.com/gofrs/flock v0.8.1/go.mod h1:F1TvTiK9OcQqauNUHlbJvyl9Qa1QvF/gOUDKA14jxHU=
7880
github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q=
7981
github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q=
8082
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=

pkg/runtime/config.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// SPDX-FileCopyrightText: 2022-present Intel Corporation
2+
//
3+
// SPDX-License-Identifier: Apache-2.0
4+
5+
package runtime
6+
7+
type Config struct {
8+
Clusters map[string]ClusterConfig `yaml:"clusters,omitempty"`
9+
}
10+
11+
type ClusterConfig struct {
12+
Name string `yaml:"name"`
13+
Driver DriverConfig `yaml:"driver,omitempty"`
14+
Config map[string]interface{} `yaml:"config,omitempty"`
15+
}
16+
17+
type DriverConfig struct {
18+
Name string `yaml:"name"`
19+
Version string `yaml:"version"`
20+
}

0 commit comments

Comments
 (0)