Skip to content

Commit

Permalink
feat(hello-world-example): use arm nodes on development environment a…
Browse files Browse the repository at this point in the history
…nd x86 on staging/prod (#279)

Co-authored-by: Andrew Peabody <andrewpeabody@google.com>
  • Loading branch information
caetano-colin and apeabody authored Nov 21, 2024
1 parent 5ec49b3 commit 03b2db6
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 8 deletions.
16 changes: 13 additions & 3 deletions 6-appsource/hello-world/README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,22 @@
### Example: Getting started with a simple go app
# Example: Getting started with a simple go app

This is a simple example based on:
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:

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

### Using the CI/CD Pipeline
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.

| | Development | Non Production/Staging | Production | |
|--------------|-------------|------------------------|------------|---|
| Architecture | arm64 | amd64/x86 | amd64/x86 | |

To achieve multi-architecture builds and images, the examples needs to use the extended features of [`buildx`](https://github.com/docker/buildx).

## Using the CI/CD Pipeline

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.

1. Clone the CI/CD repository

Expand Down
26 changes: 21 additions & 5 deletions 6-appsource/hello-world/cloudbuild.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,25 @@
# limitations under the License.

steps:
- name: gcr.io/k8s-skaffold/skaffold:v2.13.2
- name: 'gcr.io/cloud-builders/docker:20.10.3'
args: ['run', '--privileged', 'linuxkit/binfmt:v0.7']
id: 'initialize-qemu'
- name: 'gcr.io/cloud-builders/docker:20.10.3'
args: ['buildx', 'create', '--name', 'multiarch', "--use"]
id: 'create-builder-and-use'
- name: 'gcr.io/cloud-builders/docker:20.10.3'
args: ['buildx', 'inspect', '--bootstrap']
id: 'show-target-build-platforms'
- name: 'gcr.io/cloud-builders/docker:20.10.3'
entrypoint: sh
args:
- "skaffold"
- "build"
- "--file-output=/workspace/artifacts.json"
- "--default-repo=$_CONTAINER_REGISTRY"
- "-c"
- |
apk add --no-cache curl
curl -Lo skaffold https://storage.googleapis.com/skaffold/releases/latest/skaffold-linux-amd64 && \
install skaffold /usr/local/bin/
skaffold build --file-output=/workspace/artifacts.json --default-repo=$_CONTAINER_REGISTRY --cache-artifacts=false
id: build-multi-arch-image
- name: gcr.io/cloud-builders/gcloud
args:
- "deploy"
Expand All @@ -30,5 +43,8 @@ steps:
- "--gcs-source-staging-dir=$_SOURCE_STAGING_BUCKET/$SHORT_SHA"
- "--skaffold-file=skaffold.yaml"
- "--region=$LOCATION"
id: start-release-pipeline
options:
logging: CLOUD_LOGGING_ONLY
env:
- 'DOCKER_CLI_EXPERIMENTAL=enabled'
24 changes: 24 additions & 0 deletions 6-appsource/hello-world/k8s-pod-arm64.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Copyright 2024 Google LLC
#
# 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,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

apiVersion: v1
kind: Pod
metadata:
name: getting-started
spec:
nodeSelector:
cloud.google.com/machine-family: t2a
containers:
- name: getting-started
image: skaffold-example
7 changes: 7 additions & 0 deletions 6-appsource/hello-world/skaffold.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,17 @@ build:
variant: CommitSha
artifacts:
- image: skaffold-example
platforms: ["linux/arm64", "linux/amd64"]
custom:
buildCommand: |
docker buildx build --platform=$PLATFORMS --tag=$IMAGE --push .
manifests:
rawYaml:
- k8s-pod.yaml
profiles:
- name: development
manifests:
rawYaml:
- k8s-pod-arm64.yaml
- name: staging
- name: production

0 comments on commit 03b2db6

Please sign in to comment.