Difference between revisions of "Kaniko dockerfile"

From UVOO Tech Wiki
Jump to navigation Jump to search
 
(3 intermediate revisions by the same user not shown)
Line 2: Line 2:
  
 
https://github.com/GoogleContainerTools/kaniko
 
https://github.com/GoogleContainerTools/kaniko
 +
 +
```
 +
apiVersion: v1
 +
kind: Pod
 +
metadata:
 +
  name: kaniko-build
 +
  namespace: foo
 +
spec:
 +
  initContainers:
 +
  - name: git-clone
 +
    image: alpine
 +
    command: ["sh", "-c"]
 +
    args:
 +
    - |
 +
      apk add git
 +
      git clone https://github.com/uvoo/containers.git /workspace
 +
    volumeMounts:
 +
    - name: workspace
 +
      mountPath: /workspace
 +
  containers:
 +
  - name: build-image
 +
    image: gcr.io/kaniko-project/executor:latest
 +
    args:
 +
      - "--context=dir:///workspace/test"
 +
      - "--skip-tls-verify=true"
 +
      - "--destination=harbor.example.com/demo/test"
 +
    volumeMounts:
 +
    - name: workspace
 +
      mountPath: /workspace
 +
    - mountPath: /kaniko/.docker/
 +
      name: docker-config
 +
  volumes:
 +
  - name: workspace
 +
  - name: docker-config
 +
    configMap:
 +
      name: docker-config
 +
```
 +
 +
config.json
 +
```
 +
{
 +
  "auths": {
 +
    "harbor.example.com": {
 +
      "auth": "echo -n USER:PASS | base64"
 +
    }
 +
  }
 +
}
 +
```
 +
 +
main.sh
 +
```
 +
#!/bin/bash
 +
set -eu
 +
kubectl config set-context --current --namespace=foo
 +
kubectl create configmap cabundle --from-file=cabundle --save-config --dry-run=client -o yaml | kubectl apply -f -
 +
kubectl create configmap docker-config --from-file=config.json --save-config --dry-run=client -o yaml | kubectl apply -f -
 +
```
 +
 +
mountPath": "/kaniko/ssl/certs/
  
  
Line 11: Line 70:
 
- https://github.com/GoogleContainerTools/kaniko/issues/1209
 
- https://github.com/GoogleContainerTools/kaniko/issues/1209
 
- https://github.com/GoogleContainerTools/kaniko/issues/1415
 
- https://github.com/GoogleContainerTools/kaniko/issues/1415
 +
 +
 +
https://github.com/jpetazzo/container.training/blob/main/slides/k8s/build-with-kaniko.md
 +
 +
# Azure Container Registry
 +
- https://github.com/GoogleContainerTools/kaniko#pushing-to-azure-container-registry
 +
 +
# Git Sync
 +
- https://stackoverflow.com/questions/53683594/how-to-clone-a-private-git-repository-into-a-kubernetes-pod-using-ssh-keys-in-se

Latest revision as of 23:37, 24 January 2023

Builders docker image from dockerfile in k8s container

https://github.com/GoogleContainerTools/kaniko

apiVersion: v1
kind: Pod
metadata:
  name: kaniko-build
  namespace: foo
spec:
  initContainers:
  - name: git-clone
    image: alpine
    command: ["sh", "-c"]
    args:
    - |
      apk add git
      git clone https://github.com/uvoo/containers.git /workspace
    volumeMounts:
    - name: workspace
      mountPath: /workspace
  containers:
  - name: build-image
    image: gcr.io/kaniko-project/executor:latest
    args:
      - "--context=dir:///workspace/test"
      - "--skip-tls-verify=true"
      - "--destination=harbor.example.com/demo/test"
    volumeMounts:
    - name: workspace
      mountPath: /workspace
    - mountPath: /kaniko/.docker/
      name: docker-config
  volumes:
  - name: workspace
  - name: docker-config
    configMap:
      name: docker-config

config.json

{
  "auths": {
    "harbor.example.com": {
      "auth": "echo -n USER:PASS | base64"
    }
  }
}

main.sh

#!/bin/bash
set -eu
kubectl config set-context --current --namespace=foo
kubectl create configmap cabundle --from-file=cabundle --save-config --dry-run=client -o yaml | kubectl apply -f -
kubectl create configmap docker-config --from-file=config.json --save-config --dry-run=client -o yaml | kubectl apply -f -

mountPath": "/kaniko/ssl/certs/

https://blog.csanchez.org/2020/09/15/building-docker-images-with-kaniko-pushing-to-docker-registries/

https://docs.gitlab.com/ee/ci/docker/using_kaniko.html

https://github.com/jpetazzo/container.training/blob/main/slides/k8s/build-with-kaniko.md

Azure Container Registry

Git Sync