---
# System prepended metadata

title: Skaffold CI/CD

---

# Skaffold CI/CD

## Skaffold

### Why Skaffold
- To collect and specify how artifacts(docker images) are built and deployed, in a **single**, **uniformed** and **descriptive** file (skaffold.yaml.)
- To build/deploy openfaas function images with docker build/kubectl instead of faas-cli build/deploy.

### Install
Download and install the latest stable version of skaffold:
```console
curl -Lo skaffold https://storage.googleapis.com/skaffold/releases/latest/skaffold-darwin-amd64 && chmod +x skaffold && sudo mv 
skaffold /usr/local/bin
```

### Configuration
To develop with skaffold, we need to configure skaffold well to suit our needs, including:

- Docker login:
```console
docker login --username developer --password pentium cr-dev.pentium.network
```

- Default-repo setting:
```console
skaffold config set default-repo cr-dev.pentium.network
```

### Basic Skaffold.yaml
```yaml
apiVersion: skaffold/v1beta11
kind: Config

build:
  artifacts:
  - image: gateone # image name, excluding the 'host' of the url, cauz we will prepend with 'default-repo.'
    context: gateone # path to the directory where we start to add our resources.
    docker: # any docker config goes here
      dockerfile: dockerfile # path to the Dockerfile, starting from the previous 'context'
      noCache: false # used to pass in --no-cache to docker build to prevent caching.

deploy:
  kustomize: 
    path: github.com/pnetwork/pnbase//default/pentium.gateone/?ref=s/225/mike_gateone # path to the kustomization.yaml that we use to deploy the artifacts
```
For more configurable options please refer to the [skaffold.yaml](https://skaffold.dev/docs/references/yaml/) documentaiton.

## Makefile

### Make pre-build
- To define a stage where to **collect** and **generate resources** so skaffold can build the image.
- For repos that don't need any 'pre-process' before `docker build`, this step is not necessary.

### Examplary Makefile
- Platform openfaas function:
```cmake
.PHONY: pre-build

pre-build:
	cd v2/api && npm install && npm run faas-build
    # install modules and run 'faas-build' script defined in package.json
```

- Core openfaas function:
```cmake
.PHONY: pre-build

pre-build:
	mkdir -p template && \
	ofsm template -l python3-flask template && \
	faas-cli build --name=domainmanagement --lang=python3-flask --image=domainmanagement --handler=. --shrinkwrap
    # pull faas template and generate assets required to build the image
```

## Development Pipelines

### Generate Prerequisites
```console
make pre-build
```

### Build Assets
```console
skaffold build -q > build.out # build artifacts and store the outputs to build.out
```

### Deploy Built Assets
```console
skaffold deploy -a build.out # deploy built artifacts (with underlying kustomize and kubectl)
```

### Delete Assets
```console
skaffold delete # delete the deployed artifacts
```

## Reference
https://skaffold.dev/