Skip to content

Commit

Permalink
improve CI
Browse files Browse the repository at this point in the history
Signed-off-by: YZ775 <yuzuki-mimura@cybozu.co.jp>
  • Loading branch information
YZ775 committed Oct 31, 2023
1 parent bd5fe3c commit de3f937
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 78 deletions.
71 changes: 38 additions & 33 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ env:
go-version: "1.20"
filename: 'main.yaml'
jobs:
build:
name: Build
stacik-check:
name: Staic Check
runs-on: ubuntu-22.04
steps:
- name: Checkout
Expand All @@ -20,9 +20,6 @@ jobs:
with:
go-version: ${{ env.go-version }}

- name: Start etcd container
run: docker run -d --network host gcr.io/etcd-development/etcd:v3.5.7

- name: Install test tools
run: make SUDO="sudo" test-tools

Expand All @@ -32,30 +29,51 @@ jobs:
- name: Run code check tools
run: make code-check

unit-test:
name: Unit Test
runs-on: ubuntu-22.04
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Setup golang
uses: actions/setup-go@v3
with:
go-version: ${{ env.go-version }}

- name: Install test tools
run: make SUDO="sudo" test-tools

- name: Build binaries
run: make build
- name: Check e2e
run: echo $RUN_E2E

- name: Run test
run: make test

- name: Prepare for uploading sabakan binaries
run: |
mkdir /tmp/workspace
cp ./sabakan ./sabactl ./sabakan-cryptsetup /tmp/workspace
cp LICENSE /tmp/workspace
e2e-test:
name: e2e Test
runs-on: ubuntu-22.04
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Upload sabakan binaries
uses: actions/upload-artifact@v3
- name: Setup golang
uses: actions/setup-go@v3
with:
name: sabakan-binaries
path: /tmp/workspace
retention-days: 1
go-version: ${{ env.go-version }}

- name: Install test tools
run: make SUDO="sudo" test-tools

- name: Build binaries
run: make build

- name: Run test
run: make e2e

build-image:
name: Build Images
runs-on: ubuntu-22.04
needs: build
steps:
- name: Checkout
uses: actions/checkout@v3
Expand All @@ -64,25 +82,12 @@ jobs:
uses: actions/setup-go@v3
with:
go-version: ${{ env.go-version }}

- name: Download sabakan binaries
uses: actions/download-artifact@v3
with:
name: sabakan-binaries
path: ./docker

- name: Build sabakan image
run: docker build -t quay.io/cybozu/sabakan:latest ./docker

- name: Save Image
run: |
mkdir -p /tmp/docker
docker save quay.io/cybozu/sabakan:latest -o /tmp/docker/image
- name: Build image
run: make docker-build

mtest:
name: Multi-host test
runs-on: ubuntu-22.04
needs: build
steps:
- name: Checkout
uses: actions/checkout@v3
Expand Down
10 changes: 2 additions & 8 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,9 @@ jobs:
with:
go-version: ${{ env.go-version }}

- name: Build Binaries
run: |
make build
cp LICENSE ./docker
cp ./sabakan ./sabactl ./sabakan-cryptsetup ./docker
- name: Build image
run: docker build -t quay.io/cybozu/sabakan:latest ./docker

run: make docker-build
- name: Push docker image to Quay.io
run: |
echo ${{ secrets.QUAY_PASSWORD }} | docker login -u ${{ secrets.QUAY_USER }} --password-stdin quay.io
Expand Down
9 changes: 5 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,11 @@ etcd:
rm -rf /tmp/etcd-v${ETCD_VERSION}-linux-amd64.tar.gz /tmp/etcd; \
fi

.PHONY: docker-build-local
docker-build-local:build
cp sabactl sabakan sabakan-cryptsetup LICENSE ./docker/
docker build -t $(IMAGE):$(TAG) ./docker
.PHONY: docker-build
docker-build: build
cp LICENSE ./docker
cp ./sabakan ./sabactl ./sabakan-cryptsetup ./docker
docker build --no-cache -t $(IMAGE):$(TAG) ./docker
rm ./docker/sabactl ./docker/sabakan ./docker/sabakan-cryptsetup ./docker/LICENSE

.PHONY: setup-cfssl
Expand Down
2 changes: 1 addition & 1 deletion bin/run-mtest.sh
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ git checkout -qf ${GITHUB_SHA}
cd mtest
cp /assets/etcd-*.tar.gz .
cp /assets/ubuntu-*.img .
make setup
make SUDO="sudo" setup
make placemat
sleep 3
exec make test TARGET="${TARGET}"
Expand Down
11 changes: 0 additions & 11 deletions e2e/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,6 @@ const (
sabakanTLSKeyFile = "./certs/server.key.insecure"
)

var ci = false

func init() {
ci = os.Getenv("CI") == "true"
}

func testMain(m *testing.M) (int, error) {
stopEtcd := runEtcd()
defer func() {
Expand Down Expand Up @@ -78,11 +72,6 @@ func runEtcd() func() {
}

func TestMain(m *testing.M) {
if ci {
code := m.Run()
os.Exit(code)
}

if len(os.Getenv("RUN_E2E")) == 0 {
os.Exit(0)
}
Expand Down
27 changes: 10 additions & 17 deletions mtest/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ SSH_PRIVKEY = $(realpath ./mtest_key)
OUTPUT := ./output
COREOS_IMAGE := flatcar_production_qemu_image.img
SABAKAN_IMAGE := $(abspath $(OUTPUT))/sabakan.img
SABAKAN_IMAGE_URL := quay.io/cybozu/sabakan:dev
SABAKAN_IMAGE_NAME := quay.io/cybozu/sabakan
SABAKAN_IMAGE_TAG := dev
SABAKAN_IMAGE_URL := $(SABAKAN_IMAGE_NAME):$(SABAKAN_IMAGE_TAG)
CT := $(abspath $(OUTPUT))/ct
ETCD := $(abspath $(OUTPUT))/etcd
ETCDCTL := $(abspath $(OUTPUT))/etcdctl
Expand Down Expand Up @@ -90,11 +92,7 @@ $(OUTPUT)/etcd $(OUTPUT)/etcdctl: $(ETCD_ARCHIVE)
touch $@

$(OUTPUT)/sabakan.img:
GOBIN=$(shell pwd)/../docker CGO_ENABLED=0 go install ../pkg/sabakan
GOBIN=$(shell pwd)/../docker CGO_ENABLED=0 go install ../pkg/sabakan-cryptsetup
GOBIN=$(shell pwd)/../docker CGO_ENABLED=0 go install ../pkg/sabactl
cp ../LICENSE $(shell pwd)/../docker
sudo docker build --no-cache --rm=false -t $(SABAKAN_IMAGE_URL) ../docker/
make -C ../ IMG=$(SABAKAN_IMAGE_NAME) TAG=$(SABAKAN_IMAGE_TAG) docker-build
mkdir -p $(OUTPUT)
sudo docker save $(SABAKAN_IMAGE_URL) > $@

Expand All @@ -115,32 +113,27 @@ $(CT):
curl -fsSL -o $@ https://github.com/flatcar/container-linux-config-transpiler/releases/download/v$(CT_VERSION)/ct-v$(CT_VERSION)-x86_64-unknown-linux-gnu
chmod +x $@

$(OUTPUT)/host.ign: host-ign.yml $(CT)
$(OUTPUT)/host.ign: host-ign.yml $(CT) $(CERTS)
mkdir -p $(OUTPUT)
$(CT) -strict -in-file=$< -pretty -out-file=$@
$(CT) -strict -in-file=host-ign.yml --files-dir=. -pretty -out-file=$@
# rm host-ign.yml.tmp

$(OUTPUT)/host1.ign: $(OUTPUT)/host.ign $(CERTS)
$(OUTPUT)/host1.ign: $(OUTPUT)/host.ign
sed -e 's/__BRIDGE_ADDRESS__/$(BRIDGE_ADDRESS)/' \
-e 's@__SERVER_CERT__@$(SERVER_CERT)@' \
-e 's@__SERVER_KEY__@$(SERVER_KEY)@' \
-e 's/__HOST_NAME__/host1/' \
-e 's/__HOST1__/$(HOST1)/' \
-e 's/__HOST__/$(HOST1)/g' \
-e 's/__HOST_ADDRESS__/$(HOST1)/' $< > $@

$(OUTPUT)/host2.ign: $(OUTPUT)/host.ign $(CERTS)
sed -e 's/__BRIDGE_ADDRESS__/$(BRIDGE_ADDRESS)/' \
-e 's@__SERVER_CERT__@$(SERVER_CERT)@' \
-e 's@__SERVER_KEY__@$(SERVER_KEY)@' \
-e 's/__HOST_NAME__/host2/' \
-e 's/__HOST1__/$(HOST1)/' \
-e 's/__HOST__/$(HOST2)/g' \
-e 's/__HOST_ADDRESS__/$(HOST2)/' $< > $@

$(OUTPUT)/host3.ign: $(OUTPUT)/host.ign $(CERTS)
sed -e 's/__BRIDGE_ADDRESS__/$(BRIDGE_ADDRESS)/' \
-e 's@__SERVER_CERT__@$(SERVER_CERT)@' \
-e 's@__SERVER_KEY__@$(SERVER_KEY)@' \
-e 's/__HOST_NAME__/host3/' \
-e 's/__HOST1__/$(HOST1)/' \
-e 's/__HOST__/$(HOST3)/g' \
Expand All @@ -151,10 +144,9 @@ $(OUTPUT)/readnvram:

$(CERTS):
cd ./certs && ./gencerts.sh
$(eval SERVER_CERT := $(shell cat ./certs/server.crt))
$(eval SERVER_KEY := $(shell cat ./certs/server.key.insecure))

$(IGNITIONS)/files/etc/sabakan/sabakan-tls-ca.crt: $(CERTS)
mkdir -p $(IGNITIONS)/files/etc/sabakan
cp $(OUTPUT)/certs/ca.crt $(IGNITIONS)/files/etc/sabakan/sabakan-tls-ca.crt

# Targets
Expand Down Expand Up @@ -184,3 +176,4 @@ clean:
.PHONY: setup
setup:
go install github.com/onsi/ginkgo/v2/ginkgo
sudo make -C ../ setup-cfssl
6 changes: 2 additions & 4 deletions mtest/host-ign.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,12 @@ storage:
filesystem: root
mode: 0644
contents:
inline: |
__SERVER_CERT__
local: ./output/certs/server.crt
- path: "/etc/sabakan/server.key"
filesystem: root
mode: 0644
contents:
inline: |
__SERVER_KEY__
local: ./output/certs/server.key.insecure
directories:
- filesystem: root
path: "/opt/bin"
Expand Down
Empty file.

0 comments on commit de3f937

Please sign in to comment.