Skip to content

Commit

Permalink
Arm build (#282)
Browse files Browse the repository at this point in the history
* update release pipeline to enable multi-platform images

* update docker build target

* add latest tag

* Fix release pipeline in arm-build branch (#281)

* use source branch as its versioning maintenance branch

* loosen the timecheck for requeueAfter

* change version scheme

* Bump version to 0.48-arm.25

---------

Co-authored-by: Jiawei Du <jiadu@microsoft.com>
Co-authored-by: eclipse-symphoy-bot <symphony-bot@eclipse.org>

* Bump version to 0.48-arm.26

* tag multi-platform images

* use docker buildx imagetools instead

* Bump version to 0.48-arm.27

* revert version numbers to main

---------

Co-authored-by: Jiawei Du <59427055+msftcoderdjw@users.noreply.github.com>
Co-authored-by: Jiawei Du <jiadu@microsoft.com>
Co-authored-by: eclipse-symphoy-bot <symphony-bot@eclipse.org>
  • Loading branch information
4 people authored May 31, 2024
1 parent 6156e30 commit 13e391a
Show file tree
Hide file tree
Showing 5 changed files with 107 additions and 67 deletions.
46 changes: 23 additions & 23 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,22 @@ env:
# github.repository_owner / secrets.GITHUB_TOKEN is used to login to the docker registry and helm registry and to create the release
jobs:
build:
if: github.repository == 'eclipse-symphony/symphony' && (github.actor == 'chgennar' || github.actor == 'juancooldude' || github.actor == 'Haishi2016' || github.actor == 'nonsocode' || github.actor == 'msftcoderdjw' || github.actor == 'TonyXiaofeng' || github.actor == 'iwangjintian')
if: github.repository == 'eclipse-symphony/symphony' && github.event_name != 'pull_request' && (github.actor == 'chgennar' || github.actor == 'juancooldude' || github.actor == 'Haishi2016' || github.actor == 'nonsocode' || github.actor == 'msftcoderdjw' || github.actor == 'TonyXiaofeng' || github.actor == 'iwangjintian')
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
with:
token: ${{ secrets.BOT_GITHUB_TOKEN }}

- name: Extract branch name
shell: bash
run: echo "branch=${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}" >> $GITHUB_OUTPUT
id: extract_branch

- name: Print branch name
run: echo ${{ steps.extract_branch.outputs.branch }}

- name: Install dependencies
run: |
sudo apt-get update && sudo apt-get install -y make gcc
Expand Down Expand Up @@ -82,14 +90,14 @@ jobs:
- name: Build Symphony Api
run: |
cd api
mage dockerBuild
mage dockerBuildTargetAgent
mage dockerBuildPollAgent
mage dockerBuildAPIMultiPlatform
mage dockerBuildTargetAgentMultiPlatform
mage dockerBuildPollAgentMultiPlatform
- name: Build Symphony k8s
run: |
cd k8s
mage dockerBuild
mage dockerBuildK8sMultiPlatform
- name: Replace version in cli/cmd/up.go
run: |
Expand Down Expand Up @@ -122,26 +130,18 @@ jobs:
- name: Push symphony api images
run: |
docker tag ${{ env.ContainerRegistryRepo }}/symphony-api ${{ env.ContainerRegistryRepo }}/symphony-api:${{ steps.increment_version.outputs.version }}
docker push ${{ env.ContainerRegistryRepo }}/symphony-api:${{ steps.increment_version.outputs.version }}
docker tag ${{ env.ContainerRegistryRepo }}/symphony-api:${{ steps.increment_version.outputs.version }} ${{ env.ContainerRegistryRepo }}/symphony-api:latest
docker push ${{ env.ContainerRegistryRepo }}/symphony-api:latest
docker tag ${{ env.ContainerRegistryRepo }}/symphony-target-agent ${{ env.ContainerRegistryRepo }}/symphony-target-agent:${{ steps.increment_version.outputs.version }}
docker push ${{ env.ContainerRegistryRepo }}/symphony-target-agent:${{ steps.increment_version.outputs.version }}
docker tag ${{ env.ContainerRegistryRepo }}/symphony-target-agent:${{ steps.increment_version.outputs.version }} ${{ env.ContainerRegistryRepo }}/symphony-target-agent:latest
docker push ${{ env.ContainerRegistryRepo }}/symphony-target-agent:latest
docker tag ${{ env.ContainerRegistryRepo }}/symphony-poll-agent ${{ env.ContainerRegistryRepo }}/symphony-poll-agent:${{ steps.increment_version.outputs.version }}
docker push ${{ env.ContainerRegistryRepo }}/symphony-poll-agent:${{ steps.increment_version.outputs.version }}
docker tag ${{ env.ContainerRegistryRepo }}/symphony-poll-agent:${{ steps.increment_version.outputs.version }} ${{ env.ContainerRegistryRepo }}/symphony-poll-agent:latest
docker push ${{ env.ContainerRegistryRepo }}/symphony-poll-agent:latest
docker buildx imagetools create -t ${{ env.ContainerRegistryRepo }}/symphony-api:latest ${{ env.ContainerRegistryRepo }}/symphony-api-multi:latest
docker buildx imagetools create -t ${{ env.ContainerRegistryRepo }}/symphony-api:${{ steps.increment_version.outputs.version }} ${{ env.ContainerRegistryRepo }}/symphony-api-multi:latest
docker buildx imagetools create -t ${{ env.ContainerRegistryRepo }}/symphony-target-agent:latest ${{ env.ContainerRegistryRepo }}/symphony-target-agent-multi:latest
docker buildx imagetools create -t ${{ env.ContainerRegistryRepo }}/symphony-target-agent:${{ steps.increment_version.outputs.version }} ${{ env.ContainerRegistryRepo }}/symphony-target-agent-multi:latest
docker buildx imagetools create -t ${{ env.ContainerRegistryRepo }}/symphony-poll-agent:latest ${{ env.ContainerRegistryRepo }}/symphony-poll-agent-multi:latest
docker buildx imagetools create -t ${{ env.ContainerRegistryRepo }}/symphony-poll-agent:${{ steps.increment_version.outputs.version }} ${{ env.ContainerRegistryRepo }}/symphony-poll-agent-multi:latest
- name: Push symphony k8s images
run: |
docker tag ${{ env.ContainerRegistryRepo }}/symphony-k8s ${{ env.ContainerRegistryRepo }}/symphony-k8s:${{ steps.increment_version.outputs.version }}
docker push ${{ env.ContainerRegistryRepo }}/symphony-k8s:${{ steps.increment_version.outputs.version }}
docker tag ${{ env.ContainerRegistryRepo }}/symphony-k8s:${{ steps.increment_version.outputs.version }} ${{ env.ContainerRegistryRepo }}/symphony-k8s:latest
docker push ${{ env.ContainerRegistryRepo }}/symphony-k8s:latest
docker buildx imagetools create -t ${{ env.ContainerRegistryRepo }}/symphony-k8s:latest ${{ env.ContainerRegistryRepo }}/symphony-k8s-multi:latest
docker buildx imagetools create -t ${{ env.ContainerRegistryRepo }}/symphony-k8s:${{ steps.increment_version.outputs.version }} ${{ env.ContainerRegistryRepo }}/symphony-k8s-multi:latest
- name: Push symphony helm package
run: |
cd packages/helm
Expand All @@ -161,7 +161,7 @@ jobs:
uses: ad-m/github-push-action@master
with:
github_token: ${{ secrets.BOT_GITHUB_TOKEN }}
branch: main
branch: ${{ steps.extract_branch.outputs.branch }}

- name: Create Release
id: create_release
Expand Down
7 changes: 0 additions & 7 deletions api/magefile.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,3 @@ func testHelper() error {
}
return nil
}

func DockerBuildTargetAgent() error {
return shellcmd.Command("docker-compose -f docker-compose-target-agent.yaml build").Run()
}
func DockerBuildPollAgent() error {
return shellcmd.Command("docker-compose -f docker-compose-poll-agent.yaml build").Run()
}

This file was deleted.

12 changes: 6 additions & 6 deletions k8s/reconcilers/update_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ var _ = Describe("Calling 'AttemptUpdate' on object", func() {
Expect(object.Status.ProvisioningStatus.Status).To(Equal("Succeeded"))
})
It("should requue after some time", func() {
Expect(reconcileResult.RequeueAfter).To(BeWithin("1ms").Of(TestReconcileInterval))
Expect(reconcileResult.RequeueAfter).To(BeWithin("10ms").Of(TestReconcileInterval))
})
})

Expand All @@ -163,7 +163,7 @@ var _ = Describe("Calling 'AttemptUpdate' on object", func() {
})

It("should requue after some time", func() {
Expect(reconcileResult.RequeueAfter).To(BeWithin("1ms").Of(TestPollInterval))
Expect(reconcileResult.RequeueAfter).To(BeWithin("10ms").Of(TestPollInterval))
})
})

Expand All @@ -181,7 +181,7 @@ var _ = Describe("Calling 'AttemptUpdate' on object", func() {
})

It("should requue after some time", func() {
Expect(reconcileResult.RequeueAfter).To(BeWithin("1ms").Of(TestPollInterval))
Expect(reconcileResult.RequeueAfter).To(BeWithin("10ms").Of(TestPollInterval))
})
})

Expand Down Expand Up @@ -252,7 +252,7 @@ var _ = Describe("Calling 'AttemptUpdate' on object", func() {
Expect(object.Status.ProvisioningStatus.Status).To(Equal("Reconciling"))
})
It("should requue after some time", func() {
Expect(reconcileResult.RequeueAfter).To(BeWithin("1ms").Of(TestPollInterval))
Expect(reconcileResult.RequeueAfter).To(BeWithin("10ms").Of(TestPollInterval))
})
It("should updpate the compoent status with progress", func() {
Expect(object.Status.Properties["targets.default-target.comp1"]).To(ContainSubstring("updated"))
Expand Down Expand Up @@ -282,7 +282,7 @@ var _ = Describe("Calling 'AttemptUpdate' on object", func() {
Expect(object.Status.ProvisioningStatus.Status).To(ContainSubstring("Reconciling"))
})
It("should requue after some time", func() {
Expect(reconcileResult.RequeueAfter).To(BeWithin("1ms").Of(TestPollInterval))
Expect(reconcileResult.RequeueAfter).To(BeWithin("10ms").Of(TestPollInterval))
})
})

Expand Down Expand Up @@ -330,7 +330,7 @@ var _ = Describe("Calling 'AttemptUpdate' on object", func() {
Expect(object.Status.ProvisioningStatus.Status).To(ContainSubstring("Reconciling"))
})
It("should requue after some time", func() {
Expect(reconcileResult.RequeueAfter).To(BeWithin("1ms").Of(TestPollInterval))
Expect(reconcileResult.RequeueAfter).To(BeWithin("10ms").Of(TestPollInterval))
})
})

Expand Down
79 changes: 78 additions & 1 deletion packages/mage/mage.go
Original file line number Diff line number Diff line change
Expand Up @@ -316,9 +316,86 @@ func CIVerify() error {
return nil
}

// ensureBuildxBuilder ensures that buildx is created and set up.
func ensureBuildxBuilder() error {
checkCmd := exec.Command("docker", "buildx", "ls")
output, err := checkCmd.CombinedOutput()
if err != nil {
return fmt.Errorf("failed to list buildx builders: %v, output: %s", err, output)
}
if !strings.Contains(string(output), "default") {
createCmd := exec.Command("docker", "buildx", "create", "--use", "--name", "default")
createOutput, err := createCmd.CombinedOutput()
if err != nil {
return fmt.Errorf("failed to create buildx builder: %v, output: %s", err, createOutput)
}
fmt.Println("Created buildx builder:", string(createOutput))
} else {
fmt.Println("Buildx builder 'default' already exists.")
}
return nil
}

// buildAndPushDockerImage builds and pushes the Docker image for all specified platforms.
func buildAndPushDockerImage(dockerFile, buildContext, imageTag string) error {
if err := ensureBuildxBuilder(); err != nil {
return err
}

platforms := "linux/amd64,linux/arm64,linux/arm/v7"
buildCmd := exec.Command("docker", "buildx", "build", "--platform", platforms, "-f", dockerFile, "-t", imageTag, buildContext, "--push")
output, err := buildCmd.CombinedOutput()
if err != nil {
fmt.Println(string(output))
return fmt.Errorf("failed to build and push image with Dockerfile %s: %v, output: %s", dockerFile, err, output)
}
fmt.Println("Build and push output:", string(output)) // Debugging line

return nil
}

// buildWithDockerCompose builds the Docker image using Docker Compose.
func buildWithDockerCompose(composeFile string) error {
buildCmd := exec.Command("docker", "compose", "-f", composeFile, "build")
output, err := buildCmd.CombinedOutput()
if err != nil {
fmt.Println(string(output))
return fmt.Errorf("failed to build with Docker Compose file %s: %v, output: %s", composeFile, err, output)
}
fmt.Println("Docker Compose build output:", string(output)) // Debugging line

return nil
}

// Build docker image with docker compose.
func DockerBuild() error {
return shellcmd.Command("docker-compose -f docker-compose.yaml build").Run()
return buildWithDockerCompose("docker-compose.yaml")
}

// Build Symphony API multi-platfrom docker image
func DockerBuildAPIMultiPlatform() error {
return buildAndPushDockerImage("Dockerfile", "..", "ghcr.io/eclipse-symphony/symphony-api-multi:latest")
}

// Build Symphony K8s multi-platfrom docker image
func DockerBuildK8sMultiPlatform() error {
return buildAndPushDockerImage("Dockerfile", "..", "ghcr.io/eclipse-symphony/symphony-k8s-multi:latest")
}

// Build Symphony target agent multi-platfrom docker image
func DockerBuildTargetAgentMultiPlatform() error {
return buildAndPushDockerImage("Dockerfile.target-agent", "..", "ghcr.io/eclipse-symphony/symphony-target-agent-multi:latest")
}
func DockerBuildTargetAgent() error {
return buildWithDockerCompose("docker-compose-target-agent.yaml")
}

// Build Symphony poll agent multi-platfrom docker image
func DockerBuildPollAgentMultiPlatform() error {
return buildAndPushDockerImage("Dockerfile.target-agent", "..", "ghcr.io/eclipse-symphony/symphony-poll-agent-multi:latest")
}
func DockerBuildPollAgent() error {
return buildWithDockerCompose("docker-compose-poll-agent.yaml")
}

func DockerBuildWithOverrideImg(buildBaseImg string, targetBaseImg string) error {
Expand Down

0 comments on commit 13e391a

Please sign in to comment.