Browse your Git repositories
#!/bin/bash
# Simple solution: Build using a Job that copies local files
echo "Creating tar of source files..."
cd /home/luna/hcloud-1/notes-app
tar czf /tmp/notes-app-source.tar.gz Dockerfile requirements.txt app.py templates/
echo "Creating ConfigMap from tarball..."
kubectl create configmap notes-app-tarball \
--from-file=source.tar.gz=/tmp/notes-app-source.tar.gz \
--namespace=default \
--dry-run=client -o yaml | kubectl apply -f -
echo "Creating build job..."
cat <<'EOF' | kubectl apply -f -
apiVersion: batch/v1
kind: Job
metadata:
name: build-notes-app
namespace: default
spec:
template:
spec:
restartPolicy: Never
dnsPolicy: Default
dnsConfig:
nameservers:
- 8.8.8.8
- 1.1.1.1
nodeSelector:
kubernetes.io/arch: arm64
initContainers:
- name: extract-source
image: busybox:latest
command:
- sh
- -c
- |
cd /workspace
tar xzf /tarball/source.tar.gz
ls -la /workspace
volumeMounts:
- name: tarball
mountPath: /tarball
- name: workspace
mountPath: /workspace
containers:
- name: kaniko
image: gcr.io/kaniko-project/executor:latest
args:
- "--dockerfile=/workspace/Dockerfile"
- "--context=/workspace"
- "--destination=harbor.kratov.luiv.dev/luna_priv/notes:latest"
- "--cache=true"
volumeMounts:
- name: workspace
mountPath: /workspace
- name: docker-config
mountPath: /kaniko/.docker/
volumes:
- name: workspace
emptyDir: {}
- name: tarball
configMap:
name: notes-app-tarball
- name: docker-config
secret:
secretName: harbor-registry-secret
items:
- key: .dockerconfigjson
path: config.json
EOF
echo ""
echo "Job created! Monitor with:"
echo " kubectl get pods -l job-name=build-notes-app -w"
echo " kubectl logs -f job/build-notes-app"
# Cleanup
rm /tmp/notes-app-source.tar.gz