diff --git a/.github/workflows/build-test.yaml b/.github/workflows/build-test.yaml index 9f6b2d6c..7d70fb9e 100644 --- a/.github/workflows/build-test.yaml +++ b/.github/workflows/build-test.yaml @@ -5,15 +5,34 @@ jobs: build-test: name: Build Debos and run tests runs-on: ubuntu-latest + strategy: + matrix: + platform: + - linux/arm64 + - linux/amd64 + - linux/386 + fail-fast: false steps: - name: Repository checkout uses: actions/checkout@v2 - - name: Build container - run: | - docker build -f docker/Dockerfile -t godebos/debos . + - name: Setup QEMU + uses: docker/setup-qemu-action@v1 + + - name: Setup buildx + id: build + uses: docker/setup-buildx-action@v1 + + - name: Build + uses: docker/build-push-action@v2 + with: + builder: ${{ steps.buildx.outputs.name }} + context: . + file: docker/Dockerfile + platforms: ${{ matrix.platform }} + push: false - - name: Run unit tests + - name: Unit Test run: | docker-compose -f docker/unit-tests.test.yml \ up --build --exit-code-from=sut @@ -22,8 +41,3 @@ jobs: run: | docker-compose -f docker/recipes.test.yml \ up --build --exit-code-from=sut - - - name: Run test recipes using UML backend - run: | - docker-compose -f docker/recipes-test-uml.yml \ - up --build --exit-code-from=sut diff --git a/action.go b/action.go index deaa6dfd..07114334 100644 --- a/action.go +++ b/action.go @@ -41,8 +41,9 @@ type CommonContext struct { type DebosContext struct { *CommonContext - RecipeDir string - Architecture string + RecipeDir string + Architecture string + HostArchitecture string } type Action interface { diff --git a/actions/debootstrap_action.go b/actions/debootstrap_action.go index 506270c9..6fbe45de 100644 --- a/actions/debootstrap_action.go +++ b/actions/debootstrap_action.go @@ -191,7 +191,7 @@ func (d *DebootstrapAction) Run(context *debos.DebosContext) error { } /* FIXME drop the hardcoded amd64 assumption" */ - foreign := context.Architecture != "amd64" + foreign := context.Architecture != context.HostArchitecture if foreign { cmdline = append(cmdline, "--foreign") diff --git a/actions/recipe_test.go b/actions/recipe_test.go index ef2a755d..fd85803c 100644 --- a/actions/recipe_test.go +++ b/actions/recipe_test.go @@ -287,7 +287,8 @@ actions: } func runTestWithSubRecipes(t *testing.T, test testSubRecipe, templateVars ...map[string]string) actions.Recipe { - context := debos.DebosContext { &debos.CommonContext{}, "", "" } + context := debos.DebosContext { + CommonContext: &debos.CommonContext{}, RecipeDir: "", Architecture: "", HostArchitecture: "" } dir, err := ioutil.TempDir("", "go-debos") assert.Empty(t, err) defer os.RemoveAll(dir) diff --git a/cmd/debos/debos.go b/cmd/debos/debos.go index 0f9d6a16..7836df2d 100644 --- a/cmd/debos/debos.go +++ b/cmd/debos/debos.go @@ -6,6 +6,7 @@ import ( "log" "os" "path" + "runtime" "strings" "github.com/docker/go-units" @@ -55,9 +56,36 @@ func warnLocalhost(variable string, value string) { } } +func getHostArchitecture() (string, error) { + var arch string + switch runtime.GOARCH { + case "386": + arch = "i386" + case "amd64": + arch = "amd64" + case "arm": + arch = "armhf" + case "arm64": + arch = "arm64" + case "ppc64": + arch = "ppc64el" + case "mips": + arch = "mips" + case "mipsle": + arch = "mipsel" + case "mips64": + arch = "mips64" + case "s390x": + arch = "s390x" + default: + return "", fmt.Errorf("Unsupported CPU architecture %s", runtime.GOARCH) + } + return arch, nil +} func main() { - context := debos.DebosContext { &debos.CommonContext{}, "", "" } + context := debos.DebosContext { + CommonContext: &debos.CommonContext{}, RecipeDir: "", Architecture: "", HostArchitecture: "" } var options struct { Backend string `short:"b" long:"fakemachine-backend" description:"Fakemachine backend to use" default:"auto"` ArtifactDir string `long:"artifactdir" description:"Directory for packed archives and ostree repositories (default: current directory)"` @@ -200,6 +228,12 @@ func main() { context.Origins["recipe"] = context.RecipeDir context.Architecture = r.Architecture + context.HostArchitecture, err = getHostArchitecture() + if err != nil { + log.Printf("Unable to determine host architecture: %v\n", err) + exitcode = 1 + return + } context.State = debos.Success diff --git a/docker/Dockerfile b/docker/Dockerfile index 0bebece6..6d551f21 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -27,7 +27,10 @@ WORKDIR $GOPATH/src/github.com/stretchr/testify RUN git clone --depth 1 --branch v1.3.0 https://github.com/stretchr/testify . && \ GO111MODULE=on go get ./... -# Build debos +# Temporary fix to make thigns build +WORKDIR $GOPATH/src/github.com/go-debos/fakemachine +RUN git clone --depth 1 --branch eds/portability https://github.com/eds-collabora/fakemachine . && go get -t ./... + COPY . $GOPATH/src/github.com/go-debos/debos WORKDIR $GOPATH/src/github.com/go-debos/debos/cmd/debos RUN go get -t ./... @@ -77,7 +80,6 @@ RUN echo "deb http://deb.debian.org/debian experimental main" > /etc/apt/sources pigz \ libostree-1-1 \ libslirp-helper \ - linux-image-amd64 \ openssh-client \ parted \ pkg-config \ @@ -86,7 +88,6 @@ RUN echo "deb http://deb.debian.org/debian experimental main" > /etc/apt/sources systemd-container \ u-boot-tools \ unzip \ - user-mode-linux \ xfsprogs \ xz-utils \ zip && \