Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update demo #4

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 1 addition & 17 deletions .github/workflows/preevy-down.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,23 +34,7 @@ jobs:
location: ${{ vars.GOOGLE_CLOUD_KUBE_CLUSTER_LOCATION }}
cluster: ${{ vars.GOOGLE_CLOUD_KUBE_CLUSTER_NAME }}

# use a preexisting kubernetes builder which already has cached layers
- name: Find pod of existing kubernetes builder
id: find_pod
run: |
pod=$(kubectl get pod --selector=app='${{ vars.GOOGLE_CLOUD_KUBE_CLUSTER_BUILDER }}' -o jsonpath='{.items[0].metadata.name}')
echo "pod=${pod}" >> $GITHUB_OUTPUT

- name: Configure buildx to use the existing kubernetes builder
id: buildx_setup
uses: docker/setup-buildx-action@v3
with:
driver: remote
# https://github.com/moby/buildkit/tree/master/examples/kubernetes#pod
# uses the kube-pod connection helper: https://github.com/moby/buildkit/pull/951
endpoint: kube-pod://${{ steps.find_pod.outputs.pod }}

- uses: livecycle/preevy-down-action@f94196c17c7d53dcde0f0bb158be20fd3e08a62f
- uses: livecycle/[email protected]
with:
profile-url: ${{ vars.PREEVY_PROFILE_URL }}
install: 'gh-release'
Expand Down
24 changes: 4 additions & 20 deletions .github/workflows/preevy-up.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,34 +48,18 @@ jobs:
location: ${{ vars.GOOGLE_CLOUD_KUBE_CLUSTER_LOCATION }}
cluster: ${{ vars.GOOGLE_CLOUD_KUBE_CLUSTER_NAME }}

# use a preexisting kubernetes builder which already has cached layers
- name: Find pod of existing kubernetes builder
id: find_pod
run: |
pod=$(kubectl get pod --selector=app='${{ vars.GOOGLE_CLOUD_KUBE_CLUSTER_BUILDER }}' -o jsonpath='{.items[0].metadata.name}')
echo "pod=${pod}" >> $GITHUB_OUTPUT

- name: Configure buildx to use the existing kubernetes builder
- name: Configure buildx
id: buildx_setup
uses: docker/setup-buildx-action@v3
with:
driver: remote
# https://github.com/moby/buildkit/tree/master/examples/kubernetes#pod
# uses the kube-pod connection helper: https://github.com/moby/buildkit/pull/951
endpoint: kube-pod://${{ steps.find_pod.outputs.pod }}
driver: kubernetes

- name: Deploy Preevy environment
id: preevy_up
uses: livecycle/preevy-up-action@v2.3.0
uses: livecycle/preevy-up-action@v2.4.0
with:
install: 'gh-release'
profile-url: ${{ vars.PREEVY_PROFILE_URL }}
args: "--driver kube-pod --registry '${{ vars.GOOGLE_CLOUD_REGISTRY }}' --builder '${{ steps.buildx_setup.outputs.name }}'"
args: "--driver kube-pod --registry '${{ vars.GOOGLE_CLOUD_REGISTRY }}' --builder '${{ steps.buildx_setup.outputs.name }}' --kube-pod-template=preevy-template.yaml.njk"
env:
GITHUB_TOKEN: ${{ github.token }}

- name: Link environment to livecycle
env:
LIVECYCLE_API_KEY: ${{ secrets.LIVECYCLE_API_KEY }}
PREVIEW_URL: ${{ fromJson(steps.preevy_up.outputs.urls-map).frontend[3000] }}
run: npx @livecycle/cli link --url=$PREVIEW_URL --from-git=. --api-key=$LIVECYCLE_API_KEY
4 changes: 4 additions & 0 deletions compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ services:
- private
depends_on:
- db
links:
- db
db:
# We use a mariadb image which supports both amd64 & arm64 architecture
image: mariadb:10.6.4-focal
Expand Down Expand Up @@ -59,6 +61,8 @@ services:
- public
depends_on:
- backend
links:
- backend
networks:
public:
private:
Expand Down
104 changes: 104 additions & 0 deletions preevy-template.yaml.njk
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
---
apiVersion: v1
kind: ServiceAccount
metadata:
name: {{ id }}-sa
namespace: {{ namespace }}

---
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ id }}-dc
namespace: {{ namespace }}
data:
daemon.json: |
{
"tls": false
}
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: {{ id }}
namespace: {{ namespace }}
labels:
app.kubernetes.io/component: docker-host
spec:
replicas: 1
selector:
matchLabels:
{% for k, v in labels %}
{{ k }}: {{ v }}
{% endfor %}
template:
metadata:
labels:
{% for k, v in labels %}
{{ k }}: {{ v }}
{% endfor %}
spec:
serviceAccountName: {{ id }}-sa
containers:
- name: docker
image: docker:24.0.7-dind-alpine3.18
securityContext:
privileged: true
command: ["dockerd", "--host=tcp://0.0.0.0:2375", "--host=unix:///var/run/docker.sock"]
volumeMounts:
- name: docker-config
mountPath: /etc/docker
- name: data
subPath: docker
mountPath: /var/lib/docker
- name: data
subPath: preevy
mountPath: /var/lib/preevy
volumes:
- name: docker-config
configMap:
name: {{ id }}-dc
volumeClaimTemplates:
- metadata:
name: data
labels:
{% for k, v in labels %}
{{ k }}: {{ v }}
{% endfor %}
spec:
accessModes: ["ReadWriteOnce"]
{% if storageClass %}
storageClassName: "{{ storageClass }}"
{% endif %}
resources:
requests:
storage: {{ storageSize }}Gi
---
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
name: {{ id }}-role
namespace: {{ namespace }}
rules:
- apiGroups:
- metrics.k8s.io
- ""
resources:
- pods
verbs:
- get
- list

---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
name: {{ id }}-rolebind
namespace: {{ namespace }}
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: Role
name: {{ id }}-role
subjects:
- kind: ServiceAccount
name: {{ id }}-sa