Skip to content

Commit 03b2db6

Browse files
feat(hello-world-example): use arm nodes on development environment and x86 on staging/prod (#279)
Co-authored-by: Andrew Peabody <[email protected]>
1 parent 5ec49b3 commit 03b2db6

File tree

4 files changed

+65
-8
lines changed

4 files changed

+65
-8
lines changed

6-appsource/hello-world/README.md

+13-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,22 @@
1-
### Example: Getting started with a simple go app
1+
# Example: Getting started with a simple go app
22

3-
This is a simple example based on:
3+
This is a modified version of a [simple example](https://github.com/GoogleContainerTools/skaffold/tree/main/examples/getting-started) for skaffold, and contains the following features:
44

55
* **building** a single Go file app and with a multistage `Dockerfile` using local docker to build
66
* **tagging** using the default tagPolicy (`gitCommit`)
77
* **deploying** a single container pod using `kubectl`
88

9-
### Using the CI/CD Pipeline
9+
This example contains multi-architecture images. On the development environment, the pod specification will request arm64 nodes for the autopilot cluster and run an arm64 version of the docker image. On nonproduction and production environments, the pod will run an amd64/x86 version of the image on standard clusters.
10+
11+
| | Development | Non Production/Staging | Production | |
12+
|--------------|-------------|------------------------|------------|---|
13+
| Architecture | arm64 | amd64/x86 | amd64/x86 | |
14+
15+
To achieve multi-architecture builds and images, the examples needs to use the extended features of [`buildx`](https://github.com/docker/buildx).
16+
17+
## Using the CI/CD Pipeline
18+
19+
A CI/CD pipeline was created for this application on 5-appinfra, it uses Cloud Build to build the docker image and Cloud Deploy to deploy the image to the cluster using skaffold.
1020

1121
1. Clone the CI/CD repository
1222

6-appsource/hello-world/cloudbuild.yaml

+21-5
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,25 @@
1313
# limitations under the License.
1414

1515
steps:
16-
- name: gcr.io/k8s-skaffold/skaffold:v2.13.2
16+
- name: 'gcr.io/cloud-builders/docker:20.10.3'
17+
args: ['run', '--privileged', 'linuxkit/binfmt:v0.7']
18+
id: 'initialize-qemu'
19+
- name: 'gcr.io/cloud-builders/docker:20.10.3'
20+
args: ['buildx', 'create', '--name', 'multiarch', "--use"]
21+
id: 'create-builder-and-use'
22+
- name: 'gcr.io/cloud-builders/docker:20.10.3'
23+
args: ['buildx', 'inspect', '--bootstrap']
24+
id: 'show-target-build-platforms'
25+
- name: 'gcr.io/cloud-builders/docker:20.10.3'
26+
entrypoint: sh
1727
args:
18-
- "skaffold"
19-
- "build"
20-
- "--file-output=/workspace/artifacts.json"
21-
- "--default-repo=$_CONTAINER_REGISTRY"
28+
- "-c"
29+
- |
30+
apk add --no-cache curl
31+
curl -Lo skaffold https://storage.googleapis.com/skaffold/releases/latest/skaffold-linux-amd64 && \
32+
install skaffold /usr/local/bin/
33+
skaffold build --file-output=/workspace/artifacts.json --default-repo=$_CONTAINER_REGISTRY --cache-artifacts=false
34+
id: build-multi-arch-image
2235
- name: gcr.io/cloud-builders/gcloud
2336
args:
2437
- "deploy"
@@ -30,5 +43,8 @@ steps:
3043
- "--gcs-source-staging-dir=$_SOURCE_STAGING_BUCKET/$SHORT_SHA"
3144
- "--skaffold-file=skaffold.yaml"
3245
- "--region=$LOCATION"
46+
id: start-release-pipeline
3347
options:
3448
logging: CLOUD_LOGGING_ONLY
49+
env:
50+
- 'DOCKER_CLI_EXPERIMENTAL=enabled'
+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Copyright 2024 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
apiVersion: v1
16+
kind: Pod
17+
metadata:
18+
name: getting-started
19+
spec:
20+
nodeSelector:
21+
cloud.google.com/machine-family: t2a
22+
containers:
23+
- name: getting-started
24+
image: skaffold-example

6-appsource/hello-world/skaffold.yaml

+7
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,17 @@ build:
2020
variant: CommitSha
2121
artifacts:
2222
- image: skaffold-example
23+
platforms: ["linux/arm64", "linux/amd64"]
24+
custom:
25+
buildCommand: |
26+
docker buildx build --platform=$PLATFORMS --tag=$IMAGE --push .
2327
manifests:
2428
rawYaml:
2529
- k8s-pod.yaml
2630
profiles:
2731
- name: development
32+
manifests:
33+
rawYaml:
34+
- k8s-pod-arm64.yaml
2835
- name: staging
2936
- name: production

0 commit comments

Comments
 (0)