Skip to content
This repository was archived by the owner on Dec 9, 2024. It is now read-only.

testcase: support individual build #398

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/build.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: "Build"
on: [push, pull_request]
on: [pull_request]

jobs:
build:
16 changes: 16 additions & 0 deletions .github/workflows/build_images.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: "Build-image"
on: [pull_request]

jobs:
buildx:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- uses: docker/setup-buildx-action@v1
id: buildx
with:
install: true
- name: Build
run: |
make image
2 changes: 1 addition & 1 deletion .github/workflows/build_workflow.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: "Build-workflow"
on: [push, pull_request]
on: [pull_request]

jobs:
build:
2 changes: 1 addition & 1 deletion .github/workflows/precheck.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: "Pre-Check"
on: [push, pull_request]
on: [pull_request]

jobs:
pre-check:
2 changes: 1 addition & 1 deletion .github/workflows/test.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: "Test"
on: [push, pull_request]
on: [pull_request]

jobs:
test:
11 changes: 7 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
@@ -12,7 +12,7 @@ LDFLAGS += -X "github.com/pingcap/tipocket/pkg/test-infra/fixture.BuildHash=$(sh

GOBUILD=$(GO) build -ldflags '$(LDFLAGS)'

DOCKER_REGISTRY_PREFIX := $(if $(DOCKER_REGISTRY),$(DOCKER_REGISTRY)/,)
DOCKER_REGISTRY_TIPOCKET := $(if $(DOCKER_REGISTRY),$(DOCKER_REGISTRY)/,)tipocket

default: tidy fmt lint build

@@ -168,8 +168,9 @@ endif
groupimports: install-goimports
goimports -w -l -local github.com/pingcap/tipocket $$($(PACKAGE_DIRECTORIES))

i ?= true
init: tipocket
bin/tipocket init -c $(c)
bin/tipocket init -c=$(c) -i=$i

install-goimports:
ifeq (, $(shell which goimports))
@@ -250,9 +251,11 @@ test:
find testcase -mindepth 1 -maxdepth 1 -type d | xargs -I% sh -c 'cd %; make test';

image:
DOCKER_BUILDKIT=1 docker build -t ${DOCKER_REGISTRY_PREFIX}pingcap/tipocket:latest .
DOCKER_BUILDKIT=1 docker build -t ${DOCKER_REGISTRY_TIPOCKET}/tipocket:latest .
find testcase -mindepth 1 -maxdepth 1 -type d | xargs -I% sh -c 'if [ -f %/Dockerfile ]; then DOCKER_BUILDKIT=1 docker build -t ${DOCKER_REGISTRY_TIPOCKET}/`basename %`:latest -f %/Dockerfile .; fi';

docker-push:
docker push ${DOCKER_REGISTRY_PREFIX}pingcap/tipocket:latest
docker push ${DOCKER_REGISTRY_TIPOCKET}/tipocket:latest
find testcase -mindepth 1 -maxdepth 1 -type d | xargs -I% sh -c 'if [ -f %/Dockerfile ]; then DOCKER_BUILDKIT=1 docker push ${DOCKER_REGISTRY_TIPOCKET}/`basename %`:latest; fi';

.PHONY: all clean pocket compare test fmt
26 changes: 18 additions & 8 deletions cmd/tipocket/init.go
Original file line number Diff line number Diff line change
@@ -17,7 +17,8 @@ import (
)

var (
caseNameFlag string
caseNameFlag string
individualBuildFlag bool
)

func newInitCmd() *cobra.Command {
@@ -35,7 +36,7 @@ func newInitCmd() *cobra.Command {
RunE: func(cmd *cobra.Command, args []string) error {
scaffolder := scaffolds.NewScaffold()
universe := model.NewUniverse()
err := scaffolder.Execute(universe, &testcase.Makefile{
fileBuilders := []file.Builder{&testcase.Makefile{
TemplateMixin: file.TemplateMixin{Path: filepath.Join("testcase", caseNameFlag, "Makefile")},
CaseName: caseNameFlag,
}, &testcase.Client{
@@ -51,23 +52,32 @@ func newInitCmd() *cobra.Command {
TemplateMixin: file.TemplateMixin{Path: filepath.Join("testcase", caseNameFlag, "revive.toml")},
CaseName: caseNameFlag,
}, &template.MakefileUpdater{
InserterMixin: file.InserterMixin{Path: "Makefile"},
CaseName: caseNameFlag,
InserterMixin: file.InserterMixin{Path: "Makefile"},
CaseName: caseNameFlag,
IndividualBuild: individualBuildFlag,
}, &template.CaseJsonnetUpdater{
InserterMixin: file.InserterMixin{Path: filepath.Join("run", "lib", "case.libsonnet")},
CaseName: caseNameFlag,
}, &workflow.CaseJsonnetTemplate{
TemplateMixin: file.TemplateMixin{Path: filepath.Join("run", "workflow", fmt.Sprintf("%s.jsonnet", caseNameFlag))},
CaseName: caseNameFlag,
})
if err != nil {
TemplateMixin: file.TemplateMixin{Path: filepath.Join("run", "workflow", fmt.Sprintf("%s.jsonnet", caseNameFlag))},
CaseName: caseNameFlag,
IndividualBuild: individualBuildFlag,
}}
if individualBuildFlag {
fileBuilders = append(fileBuilders, &testcase.Dockerfile{
TemplateMixin: file.TemplateMixin{Path: filepath.Join("testcase", caseNameFlag, "Dockerfile")},
CaseName: caseNameFlag,
})
}
if err := scaffolder.Execute(universe, fileBuilders...); err != nil {
return err
}
fmt.Printf("create a new case `%[1]s`: testcase/%[1]s\n", caseNameFlag)
return nil
},
}
cmd.Flags().StringVarP(&caseNameFlag, "case-name", "c", "", "test case name")
cmd.Flags().BoolVarP(&individualBuildFlag, "individual-build", "i", false, "individual build from root image")
cmd.MarkFlagRequired("case-name")
return cmd
}
13 changes: 12 additions & 1 deletion pkg/scaffolds/template/makefile.go
Original file line number Diff line number Diff line change
@@ -15,13 +15,18 @@ const (
cd testcase/%[1]s; make build; \
cp bin/* ../../bin/

`
makefileCmdIndividualBuildInsertionTemplate = `%[1]s:
cd testcase/%[1]s; make build;

`
)

// MakefileUpdater inserts a build rule for the new test case
type MakefileUpdater struct {
file.InserterMixin
CaseName string
CaseName string
IndividualBuild bool
}

// GetIfExistsAction ...
@@ -31,6 +36,12 @@ func (m *MakefileUpdater) GetIfExistsAction() file.IfExistsAction {

// GetCodeFragments ...
func (m *MakefileUpdater) GetCodeFragments() map[file.Marker]file.CodeFragment {
if m.IndividualBuild {
return map[file.Marker]file.CodeFragment{
makefileBuildMarker: {fmt.Sprintf(makefileBuildInsertionTemplate, m.CaseName)},
makefileCmdMarker: {fmt.Sprintf(makefileCmdIndividualBuildInsertionTemplate, m.CaseName)},
}
}
return map[file.Marker]file.CodeFragment{
makefileBuildMarker: {fmt.Sprintf(makefileBuildInsertionTemplate, m.CaseName)},
makefileCmdMarker: {fmt.Sprintf(makefileCmdInsertionTemplate, m.CaseName)},
66 changes: 66 additions & 0 deletions pkg/scaffolds/template/testcase/dockerfile.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
// Copyright 2021 PingCAP, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// See the License for the specific language governing permissions and
// limitations under the License.

package testcase

import "github.com/pingcap/tipocket/pkg/scaffolds/file"

// Dockerfile uses for Dockerfile template
type Dockerfile struct {
file.TemplateMixin
CaseName string
}

// GetIfExistsAction ...
func (g *Dockerfile) GetIfExistsAction() file.IfExistsAction {
return file.IfExistsActionError
}

// Validate ...
func (g *Dockerfile) Validate() error {
return g.TemplateMixin.Validate()
}

// SetTemplateDefaults ...
func (g *Dockerfile) SetTemplateDefaults() error {
g.TemplateBody = dockerfileTemplate
return nil
}

const dockerfileTemplate = `# syntax = docker/dockerfile:1.0-experimental
FROM golang:alpine3.10 AS build_base

RUN apk add --no-cache gcc libc-dev make bash git

ENV GO111MODULE=on
WORKDIR /src
COPY . .
COPY .git .git

RUN rm -rf /go/src/
RUN --mount=type=cache,id=tipocket_go_pkg,target=/go/pkg \
--mount=type=cache,id=tipocket_go_cache,target=/root/.cache/go-build \
--mount=type=tmpfs,id=tipocket_go_src,target=/go/src/ cd testcase/{{ .CaseName }} && make build

FROM alpine:3.8

RUN apk update && apk upgrade && \
apk add --no-cache bash curl wget

RUN mkdir -p /config && mkdir -p /resources
COPY --from=0 /src/testcase/{{ .CaseName }}/bin/* /bin/
COPY --from=0 /src/config /config
COPY --from=0 /src/resources /resources

EXPOSE 8080
`
27 changes: 23 additions & 4 deletions pkg/scaffolds/template/workflow/case.jsonnet.go
Original file line number Diff line number Diff line change
@@ -18,7 +18,8 @@ import "github.com/pingcap/tipocket/pkg/scaffolds/file"
// CaseJsonnetTemplate uses for client.go
type CaseJsonnetTemplate struct {
file.TemplateMixin
CaseName string
CaseName string
IndividualBuild bool
}

// GetIfExistsAction ...
@@ -33,14 +34,19 @@ func (c *CaseJsonnetTemplate) Validate() error {

// SetTemplateDefaults ...
func (c *CaseJsonnetTemplate) SetTemplateDefaults() error {
c.TemplateBody = clientTemplate
if c.IndividualBuild {
c.TemplateBody = clientIndividualBuildTemplate
} else {
c.TemplateBody = clientTemplate
}
return nil
}

const clientTemplate = `{
const (
clientTemplate = `{
_config+:: {
case_name: '{{ .CaseName }}',
image_name: 'hub.pingcap.net/qa/tipocket',
image_name: 'hub.pingcap.net/tipocket/tipocket',
args+: {
// k8s configurations
// 'storage-class': 'local-storage',
@@ -49,3 +55,16 @@ const clientTemplate = `{
},
}
`
clientIndividualBuildTemplate = `{
_config+:: {
case_name: '{{ .CaseName }}',
image_name: 'hub.pingcap.net/tipocket/{{ .CaseName }}',
args+: {
// k8s configurations
// 'storage-class': 'local-storage',
},
command: {},
},
}
`
)
2 changes: 1 addition & 1 deletion run/README.md
Original file line number Diff line number Diff line change
@@ -30,7 +30,7 @@ After fill on the testcase metadata, I should write a workflow file on [workflow
{
_config+:: {
case_name: 'list_append',
image_name: 'hub.pingcap.net/qa/tipocket',
image_name: 'hub.pingcap.net/tipocket/tipocket',
args+: {
// k8s configurations
// 'storage-class': 'local-storage',
2 changes: 1 addition & 1 deletion run/lib/config.libsonnet
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
_config:: {
schedule: '0 0 * * *',
image_name: 'hub.pingcap.net/qa/tipocket',
image_name: 'hub.pingcap.net/tipocket/tipocket',
args: {
// cluster configurations
hub: 'docker.io',
2 changes: 1 addition & 1 deletion run/workflow/bank.jsonnet
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
_config+:: {
case_name: 'bank',
image_name: 'hub.pingcap.net/qa/tipocket',
image_name: 'hub.pingcap.net/tipocket/tipocket',
args+: {
// k8s configurations
// 'storage-class': 'local-storage',
2 changes: 1 addition & 1 deletion run/workflow/bank2.jsonnet
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
_config+:: {
case_name: 'bank2',
image_name: 'hub.pingcap.net/qa/tipocket',
image_name: 'hub.pingcap.net/tipocket/tipocket',
args+: {
// k8s configurations
// 'storage-class': 'local-storage',
2 changes: 1 addition & 1 deletion run/workflow/block-writer.jsonnet
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
_config+:: {
case_name: 'block-writer',
image_name: 'hub.pingcap.net/qa/tipocket',
image_name: 'hub.pingcap.net/tipocket/tipocket',
args+: {
// k8s configurations
// 'storage-class': 'local-storage',
2 changes: 1 addition & 1 deletion run/workflow/cross-region.jsonnet
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
_config+:: {
case_name: 'crossregion',
image_name: 'hub.pingcap.net/qa/tipocket',
image_name: 'hub.pingcap.net/tipocket:cross-region',
args+: {
// k8s configurations
// 'storage-class': 'local-storage',
2 changes: 1 addition & 1 deletion run/workflow/example.jsonnet
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
_config+:: {
case_name: 'example',
image_name: 'hub.pingcap.net/qa/tipocket',
image_name: 'hub.pingcap.net/tipocket/tipocket',
args+: {
// k8s configurations
// 'storage-class': 'local-storage',
2 changes: 1 addition & 1 deletion run/workflow/ledger.jsonnet
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
_config+:: {
case_name: 'ledger',
image_name: 'hub.pingcap.net/qa/tipocket',
image_name: 'hub.pingcap.net/tipocket/tipocket',
args+: {
// k8s configurations
// 'storage-class': 'local-storage',
2 changes: 1 addition & 1 deletion run/workflow/list-append.jsonnet
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
_config+:: {
case_name: 'list-append',
image_name: 'hub.pingcap.net/qa/tipocket',
image_name: 'hub.pingcap.net/tipocket/tipocket',
args+: {
// k8s configurations
// 'storage-class': 'local-storage',
2 changes: 1 addition & 1 deletion run/workflow/rawkv-linearizability.jsonnet
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
_config+:: {
case_name: 'rawkv_linearizability',
image_name: 'hub.pingcap.net/qa/tipocket',
image_name: 'hub.pingcap.net/tipocket/tipocket',
args+: {
// k8s configurations
// 'storage-class': 'local-storage',
2 changes: 1 addition & 1 deletion run/workflow/region-available.jsonnet
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
_config+:: {
case_name: 'region_available',
image_name: 'hub.pingcap.net/qa/tipocket',
image_name: 'hub.pingcap.net/tipocket/tipocket',
args+: {
// k8s configurations
// 'storage-class': 'local-storage',
2 changes: 1 addition & 1 deletion run/workflow/rw-register.jsonnet
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
_config+:: {
case_name: 'rw-register',
image_name: 'hub.pingcap.net/qa/tipocket',
image_name: 'hub.pingcap.net/tipocket/tipocket',
args+: {
// k8s configurations
// 'storage-class': 'local-storage',
2 changes: 1 addition & 1 deletion run/workflow/sqllogic.jsonnet
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
_config+:: {
case_name: 'sqllogic',
image_name: 'hub.pingcap.net/qa/tipocket',
image_name: 'hub.pingcap.net/tipocket/tipocket',
args+: {
// k8s configurations
// 'storage-class': 'local-storage',
2 changes: 1 addition & 1 deletion run/workflow/tpcc.jsonnet
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
_config+:: {
case_name: 'tpcc',
image_name: 'hub.pingcap.net/qa/tipocket',
image_name: 'hub.pingcap.net/tipocket/tipocket',
args+: {
// k8s configurations
// 'storage-class': 'local-storage',
2 changes: 1 addition & 1 deletion run/workflow/ttl.jsonnet
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
_config+:: {
case_name: 'ttl',
image_name: 'hub.pingcap.net/qa/tipocket',
image_name: 'hub.pingcap.net/tipocket/tipocket',
args+: {
// k8s configurations
// 'storage-class': 'local-storage',
2 changes: 1 addition & 1 deletion run/workflow/txn-rand-pessimistic.jsonnet
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
_config+:: {
case_name: 'txn_rand_pessimistic',
image_name: 'hub.pingcap.net/qa/tipocket',
image_name: 'hub.pingcap.net/tipocket/tipocket',
args+: {
// k8s configurations
// 'storage-class': 'local-storage',
2 changes: 1 addition & 1 deletion run/workflow/vbank.jsonnet
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
_config+:: {
case_name: 'vbank',
image_name: 'hub.pingcap.net/qa/tipocket',
image_name: 'hub.pingcap.net/tipocket/tipocket',
args+: {
// k8s configurations
// 'storage-class': 'local-storage',
24 changes: 21 additions & 3 deletions testcase/cross-region/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,23 @@
FROM alpine:3.9
# syntax = docker/dockerfile:1.0-experimental
FROM golang:alpine3.10 AS build_base

RUN apk update && apk add --no-cache wget bash sed
COPY ./bin/cross-region /bin/cross-region
RUN apk update && apk add --no-cache wget bash sed make git

WORKDIR /src
COPY . .
COPY .git .git

WORKDIR /src/testcase/cross-region

RUN rm -rf /go/src/
RUN --mount=type=cache,id=tipocket_go_pkg,target=/go/pkg \
--mount=type=cache,id=tipocket_go_cache,target=/root/.cache/go-build \
--mount=type=tmpfs,id=tipocket_go_src,target=/go/src/ make build

FROM alpine:3.8

RUN mkdir -p /config && mkdir -p /resources
COPY --from=0 /src/config /config
COPY --from=0 /src/resources /resources
COPY --from=0 /src/testcase/cross-region/bin/cross-region /bin/cross-region
ENTRYPOINT [ "/bin/cross-region" ]