Change from pull image to local build when run skaffold dev

175 views Asked by At

I'm trying to create a local development environment with Skaffold and k3d.

My environment consists of multiple Skaffold modules and every modules declares a dev profile. The main skaffold.yaml consists of multiple requires statement that are pointing to multiple git repos (every repo has its own skaffold configuration).

In order to prepare the cluster, when I create a cluster using k3d, I run skaffold run -p dev.

Every skaffold modules declare a profile like this:

profiles:
  - name: dev
    build:
      local:
        push: false
        useDockerCLI: false
      artifacts:
        - image: my-org/my-image
          docker: {}
          sync:
            infer:
              - '**/*.ts'

This profile is useful if I want to develop on a particular module, but when i want to setup the entire cluster, skaffold will build all the images instead of pulling them from a repo.

What I want to achieve is to build locally when I want to run skaffold dev on a particular module, but pull images when i run skaffold run against my skaffold.yaml entry point.

Is is possibile to do that?

Thanks

1

There are 1 answers

0
VonC On

What I want to achieve is to build locally when I want to run skaffold dev on a particular module, but pull images when I run skaffold run against my skaffold.yaml entry point.

Using Skaffold profile, as you do in your question for local development, is a good idea, but you could also introduce an additional profile specifically for pulling images from a repository when running the main skaffold.yaml.

You would have:

  • your existing dev profile in each module, configured for local development, allowing local builds with specific settings like push: false. It is ideal for working on individual modules.
  • a new profile for pulling images (pull-images Profile), introduced to handle the specific case where you want to pull images from a repository instead of building them locally. That profile should be defined in each module's skaffold.yaml.

The main skaffold.yaml uses requires statements to include all modules.
By specifying the pull-images profile when running skaffold run -p pull-images, it tells Skaffold to use the pull-images profile for each module. That results in pulling images for the entire cluster setup instead of building them.

That would allow you to distinguish between two scenarios:

  • local development (skaffold dev): use the dev profile for building images locally when working on individual modules.
  • cluster setup (skaffold run): use the pull-images profile to pull images from a repository for all modules when setting up the entire cluster.
┌──────────────────────────────┐   ┌──────────────────────────────┐
│ Individual Module Development│   │        Cluster Setup         │
└──────────────────────────────┘   └──────────────────────────────┘
            │                                        │            
            │                                        │            
            ▼                                        ▼            
┌──────────────────────────────┐   ┌──────────────────────────────┐
│       skaffold dev           │   │ skaffold run -p pull-images  │
└──────────────────────────────┘   └──────────────────────────────┘
            │                                        │            
            │                                        │            
            ▼                                        ▼            
┌──────────────────────────────┐   ┌──────────────────────────────┐
│          dev profile         │   │       pull-images profile    │
│      (Build Locally)         │   │    (Pull from Repository)    │
└──────────────────────────────┘   └──────────────────────────────┘

Your module Skaffold configuration would be:

profiles:
  - name: dev
    # Your existing dev profile configuration
  - name: pull-images
    build:
      artifacts:
        - image: my-org/my-image
          docker:
            buildArgs:
              PULL_IMAGE: "true"

And in your main skaffold.yaml:

requires:
  - path: ./path-to-module
    profiles: [pull-images]

Applying these changes to your example module's skaffold.yaml:

profiles:
  - name: dev
    build:
      local:
        push: false
        useDockerCLI: false
      artifacts:
        - image: my-org/my-image
          docker: {}
          sync:
            infer:
              - '**/*.ts'
  - name: pull-images
    build:
      artifacts:
        - image: my-org/my-image
          docker:
            buildArgs:
              PULL_IMAGE: "true"