Skip to content

Commit

Permalink
Merge pull request #1 from whywaita/develop
Browse files Browse the repository at this point in the history
Implement
  • Loading branch information
whywaita committed Dec 6, 2021
2 parents 53728ef + c4c0cb0 commit abe5064
Show file tree
Hide file tree
Showing 25 changed files with 3,191 additions and 0 deletions.
39 changes: 39 additions & 0 deletions .github/workflows/build-docker-sha.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: Build Docker image (sha) for Server
on:
push:
branches:
- "**"

jobs:
docker-build-sha:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- uses: docker/setup-qemu-action@v1
- uses: docker/setup-buildx-action@v1
- name: Cache Docker layers
uses: actions/cache@v2
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildx-
- name: Login to GitHub Container Registry
uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- uses: docker/metadata-action@v3
id: meta
with:
images: ghcr.io/whywaita/shoes-lxd-multi
tags: |
type=sha
- name: Build container image
uses: docker/build-push-action@v2
with:
push: true
tags: ${{ steps.meta.outputs.tags }}
context: ./server
59 changes: 59 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
name: Release
on:
push:
tags:
- "v[0-9]+.[0-9]+.[0-9]+"

jobs:
goreleaser:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Setup Go
uses: actions/setup-go@v2
with:
go-version: 1.16
- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v2
with:
version: latest
args: release --rm-dist
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
docker:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- uses: docker/setup-qemu-action@v1
- uses: docker/setup-buildx-action@v1
- name: Cache Docker layers
uses: actions/cache@v2
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildx-
- name: Login to GitHub Container Registry
uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- uses: docker/metadata-action@v3
id: meta
with:
images: ghcr.io/whywaita/shoes-lxd-multi
tags: |
type=raw,value=latest
type=semver,pattern={{raw}}
type=sha
- name: Build container image
uses: docker/build-push-action@v2
with:
push: true
tags: ${{ steps.meta.outputs.tags }}
context: ./server
48 changes: 48 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
name: Test
on:
push:
branches:
- "**"
pull_request: {}

jobs:
test:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
target:
- server
- shoes-lxd-multi
steps:
- name: Setup go
uses: actions/setup-go@v2
with:
go-version: 1.16.x
- name: Checkout
uses: actions/checkout@v2
with:
fetch-depth: 1
- name: lint
run: |
GO111MODULE=off GOBIN=$(pwd)/bin go get golang.org/x/lint/golint
bin/golint -set_exit_status ./...
- name: go vet
run: |
cd ${{ matrix.target }}
go vet ./...
- name: go test
run: |
cd ${{ matrix.target }}
go test ./...
docker-build-test:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
with:
fetch-depth: 1
- name: docker build
run: |
cd server
docker build .
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/server/server
/shoes-lxd-multi/shoes-lxd-multi

dist/
14 changes: 14 additions & 0 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
builds:
- id: "shoes-lxd-multi-shoes-provider"
dir: shoes-lxd-multi
binary: shoes-lxd-multi
env:
- CGO_ENABLED=0
- id: "shoes-lxd-multi-serevr"
dir: server
binary: shoes-lxd-multi-server
env:
- CGO_ENABLED=0
archives:
- format: binary
name_template: "{{ .Binary }}-{{ .Os }}-{{ .Arch }}"
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1 +1,8 @@
# shoes-lxd-multi

[myshoes](https://github.com/whywaita/myshoes) provider for [LXD](https://linuxcontainers.org/lxd/) in multi server.

## Architecture

- shoes-lxd-multi: shoes-provider
- server: Server-side
21 changes: 21 additions & 0 deletions server/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
FROM golang:1.16 AS builder

WORKDIR /go/src/github.com/whywaita/shoes-lxd-multi/server

ENV CGO_ENABLED=0
ENV GOOS=linux
ENV GOARCH=amd64

COPY . .
RUN go build .

FROM alpine

RUN apk update \
&& apk update
RUN apk add --no-cache ca-certificates \
&& update-ca-certificates 2>/dev/null || true

COPY --from=builder /go/src/github.com/whywaita/shoes-lxd-multi/server/server /app

CMD ["/app"]
40 changes: 40 additions & 0 deletions server/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Server

Server-side implementation for shoes-lxd-multi

## Setup

- `LXD_MULTI_HOSTS`

```json
[
{
"host": "https://192.0.2.100:8443",
"client_cert": "./node1/client.crt",
"client_key": "./node1/client.key"
},
...
]
```

### Optional values
- `LXD_MULTI_IMAGE_ALIAS`
- set runner image alias
- default: `ubuntu:bionic`
- e.g.) for remote image server: `https://192.0.2.110:8443/ubuntu-custom`
- `LXD_MULTI_RESOURCE_TYPE_MAPPING`
- mapping `resource_type` and CPU / Memory.
- need JSON format. keys is `resource_type_name`, `cpu`, `memory`.
- e.g.) `[{"resource_type_name": "nano", "cpu": 1, "memory": "1GB"}, {"resource_type_name": "micro", "cpu": 2, "memory": "2GB"}]`
- become no limit if not set resource_type.
- `LXD_MULTI_PORT`
- Port of listen gRPC Server
- default: `8080`
- `LXD_MULTI_OVER_COMMIT_PERCENT`
- Percent of able over commit in CPU
- default: `100`

## Note
LXD Server can't use `zfs` in storageclass if use `--privileged`. ref: https://discuss.linuxcontainers.org/t/docker-with-overlay-driver-in-lxd-cluster-not-working/9243

We recommend using `btrfs`.
14 changes: 14 additions & 0 deletions server/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
module github.com/whywaita/shoes-lxd-multi/server

go 1.16

require (
github.com/docker/go-units v0.4.0
github.com/lxc/lxd v0.0.0-20211202222358-a293da71aeb0
github.com/prometheus/client_golang v1.11.0
github.com/whywaita/myshoes v1.10.4
github.com/whywaita/shoes-lxd-multi/proto.go v0.0.0-20211203151606-53728ef694c2
google.golang.org/grpc v1.42.0
)

//replace github.com/flosch/pongo2 => github.com/flosch/pongo2/v4 v4.0.2
Loading

0 comments on commit abe5064

Please sign in to comment.