Skip to content

Commit 072e114

Browse files
committed
ci for express
1 parent 9ad325e commit 072e114

29 files changed

+1882
-0
lines changed

.github/workflows/E2E_CI.yaml

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
name: E2E Build
2+
3+
on:
4+
pull_request
5+
6+
jobs:
7+
8+
extract_metadata:
9+
runs-on: ubuntu-latest
10+
name: Extract supported_features
11+
outputs:
12+
supported-features: ${{ steps.supported-features.outputs.value }}
13+
steps:
14+
- name: Checkout code
15+
uses: actions/checkout@v3
16+
- name: Setup Node.js
17+
uses: actions/setup-node@v3
18+
with:
19+
node-version: '18.x'
20+
- name: extract supported features
21+
id: supported-features
22+
run: echo "value=$(node -p -e "require('./px_metadata.json').supported_features?.join(' or ') || ''")" >> "$GITHUB_OUTPUT"
23+
24+
25+
CI:
26+
runs-on: ubuntu-latest
27+
timeout-minutes: 60
28+
needs:
29+
- extract_metadata
30+
31+
steps:
32+
33+
- name: build local cluster
34+
uses: actions/checkout@v2
35+
- run: ./ci_files/build_cluster.sh
36+
37+
- name: Set up Docker
38+
uses: docker/setup-buildx-action@v1
39+
40+
- name: Build Sample-site Docker image
41+
run: |
42+
docker build -t localhost:5001/node-sample-site:1.0.0 . && docker images && docker push localhost:5001/node-sample-site:1.0.0
43+
env:
44+
DOCKER_BUILDKIT: 1
45+
46+
47+
- name: install helm
48+
run: |
49+
curl https://baltocdn.com/helm/signing.asc | gpg --dearmor | sudo tee /usr/share/keyrings/helm.gpg > /dev/null
50+
sudo apt-get install apt-transport-https --yes
51+
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/helm.gpg] https://baltocdn.com/helm/stable/debian/ all main" | sudo tee /etc/apt/sources.list.d/helm-stable-debian.list
52+
sudo apt-get update
53+
sudo apt-get install helm
54+
55+
- name: Checkout enforcer repo
56+
uses: actions/checkout@v2
57+
58+
- name: Clone helm charts repo
59+
uses: actions/checkout@v2
60+
with:
61+
repository: PerimeterX/connect-helm-charts
62+
token: ${{ secrets.CONNECT_PULL_TOKEN }}
63+
ref: main
64+
path: ./deploy_charts
65+
66+
67+
- name: deploy sample site
68+
run: |
69+
helm install sample-site ./deploy_charts/charts/sample-site --set image.name=localhost:5001/node-sample-site --set image.tag=1.0.0 --set imagePullPolicy=Always --set collectorURL=http://mock-collector-mock-collector:3001 --wait
70+
71+
- name: Set up Google Cloud SDK
72+
id: 'auth'
73+
uses: 'google-github-actions/auth@v1'
74+
with:
75+
credentials_json: '${{ secrets.GCR_SA_KEY }}'
76+
77+
- name: Configure Docker credentials
78+
run: |
79+
gcloud auth configure-docker gcr.io
80+
81+
- name: pull mock collector image
82+
run: |
83+
docker pull gcr.io/px-docker-repo/connecteam/mock-collector:1.0.2 && \
84+
docker tag gcr.io/px-docker-repo/connecteam/mock-collector:1.0.2 localhost:5001/mock-collector:1.0.2 && \
85+
docker push localhost:5001/mock-collector:1.0.2 && \
86+
docker images
87+
88+
- name: deploy mock collector
89+
run: |
90+
helm install mock-collector ./deploy_charts/charts/mock-collector --set image.repository=localhost:5001/mock-collector --set image.tag=1.0.2 --set imagePullPolicy=Always --wait
91+
92+
- run: kubectl get pods
93+
94+
- name: pull enforcer tests image
95+
run: |
96+
docker pull gcr.io/px-docker-repo/connecteam/enforcer-specs-tests:1.1.0 && \
97+
docker tag gcr.io/px-docker-repo/connecteam/enforcer-specs-tests:1.1.0 localhost:5001/enforcer-spec-tests:1.1.0 && \
98+
docker push localhost:5001/enforcer-spec-tests:1.1.0 && \
99+
docker images
100+
101+
- name: run enforcer tests
102+
run: |
103+
helm install enforcer-spec-tests ./deploy_charts/charts/enforcer-spec-tests --set image.repository=localhost:5001/enforcer-spec-tests --set image.tag=1.1.0 --set imagePullPolicy=Always \
104+
--set internalMockCollectorURL=http://mock-collector-mock-collector:3001 \
105+
--set appID=PXnEpdw6lS \
106+
--set siteURL=http://sample-site-sample-site:3000 \
107+
--set cookieSecret=${{ secrets.TEST_COOKIE_SECRET }} \
108+
--set supportedFeatures="${{ needs.extract_metadata.outputs.supported-features }}" \
109+
--set-file enforcerMetadataContent=./px_metadata.json
110+
111+
- name: wait until test is over
112+
run: ./ci_files/wait-for-job.sh
113+
env:
114+
JOB_NAME: enforcer-spec-tests
115+
116+
- name: get tests results
117+
if: ${{ failure() }}
118+
run: kubectl logs job/enforcer-spec-tests
119+
120+
- name: get tests results
121+
run: kubectl logs job/enforcer-spec-tests

Dockerfile

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# create static files and configs
2+
FROM node:16-slim
3+
4+
WORKDIR /workspace
5+
COPY ./demo-site/shared_config.json .
6+
COPY ./demo-site/scripts scripts
7+
COPY ./demo-site/templates templates
8+
COPY ./demo-site/utils utils
9+
COPY ./demo-site/servers/nodejs/package.json servers/nodejs/package.json
10+
RUN cd servers/nodejs && npm install
11+
COPY ./demo-site/servers/nodejs servers/nodejs
12+
13+
RUN node scripts/create_static_files.js && node scripts/create_px_configs.js
14+
15+
WORKDIR /workspace/servers/nodejs
16+
17+
COPY ./ perimeterx-node-express
18+
RUN npm install ./perimeterx-node-express
19+
20+
ARG ENABLE_TEST_ENDPOINTS=true
21+
ARG PX_APP_ID=""
22+
ARG PX_AUTH_TOKEN=""
23+
ARG PX_COOKIE_SECRET=""
24+
25+
ENV ENABLE_TEST_ENDPOINTS=${ENABLE_TEST_ENDPOINTS}
26+
ENV PX_APP_ID=${PX_APP_ID}
27+
ENV PX_AUTH_TOKEN=${PX_AUTH_TOKEN}
28+
ENV PX_COOKIE_SECRET=${PX_COOKIE_SECRET}
29+
30+
EXPOSE 3000
31+
CMD ["node","app.js"]

ci_files/build_cluster.sh

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
#!/bin/sh
2+
set -o errexit
3+
4+
# 1. Download kind binary
5+
# For AMD64 / x86_64
6+
#[ $(uname -m) = x86_64 ] && curl -Lo ./kind https://kind.sigs.k8s.io/dl/v0.19.0/kind-linux-amd64
7+
# For ARM64
8+
#[ $(uname -m) = aarch64 ] && curl -Lo ./kind https://kind.sigs.k8s.io/dl/v0.19.0/kind-linux-arm64
9+
#chmod +x ./kind
10+
#sudo mv ./kind /usr/local/bin/kind
11+
12+
13+
# 2. Create registry container unless it already exists
14+
reg_name='kind-registry'
15+
reg_port='5001'
16+
if [ "$(docker inspect -f '{{.State.Running}}' "${reg_name}" 2>/dev/null || true)" != 'true' ]; then
17+
docker run \
18+
-d --restart=always -p "127.0.0.1:${reg_port}:5000" --name "${reg_name}" \
19+
registry:2
20+
fi
21+
22+
# 3. Create kind cluster with containerd registry config dir enabled
23+
cat <<EOF | kind create cluster --config=-
24+
kind: Cluster
25+
apiVersion: kind.x-k8s.io/v1alpha4
26+
containerdConfigPatches:
27+
- |-
28+
[plugins."io.containerd.grpc.v1.cri".registry]
29+
config_path = "/etc/containerd/certs.d"
30+
EOF
31+
32+
# 4. Add the registry config to the nodes
33+
#
34+
# This is necessary because localhost resolves to loopback addresses that are
35+
# network-namespace local.
36+
# In other words: localhost in the container is not localhost on the host.
37+
#
38+
# We want a consistent name that works from both ends, so we tell containerd to
39+
# alias localhost:${reg_port} to the registry container when pulling images
40+
REGISTRY_DIR="/etc/containerd/certs.d/localhost:${reg_port}"
41+
for node in $(kind get nodes); do
42+
docker exec "${node}" mkdir -p "${REGISTRY_DIR}"
43+
cat <<EOF | docker exec -i "${node}" cp /dev/stdin "${REGISTRY_DIR}/hosts.toml"
44+
[host."http://${reg_name}:5000"]
45+
EOF
46+
done
47+
48+
# 5. Connect the registry to the cluster network if not already connected
49+
# This allows kind to bootstrap the network but ensures they're on the same network
50+
if [ "$(docker inspect -f='{{json .NetworkSettings.Networks.kind}}' "${reg_name}")" = 'null' ]; then
51+
docker network connect "kind" "${reg_name}"
52+
fi
53+
54+
# 6. Document the local registry
55+
# https://github.com/kubernetes/enhancements/tree/master/keps/sig-cluster-lifecycle/generic/1755-communicating-a-local-registry
56+
cat <<EOF | kubectl apply -f -
57+
apiVersion: v1
58+
kind: ConfigMap
59+
metadata:
60+
name: local-registry-hosting
61+
namespace: kube-public
62+
data:
63+
localRegistryHosting.v1: |
64+
host: "localhost:${reg_port}"
65+
help: "https://kind.sigs.k8s.io/docs/user/local-registry/"
66+
EOF

ci_files/extract_features.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/bin/bash
2+
3+
# Read JSON file as a one-liner string
4+
json_file_path="../px_metadata.json"
5+
json_string=$(cat "$json_file_path" | tr -d '\n' | tr -d ' ')
6+
7+
echo "$json_string"

ci_files/wait-for-job.sh

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#!/usr/bin/env bash
2+
3+
export job=$JOB_NAME
4+
export ns="${NAMESPACE:-default}"
5+
6+
if [ -z $job ]; then
7+
echo JOB_NAME is required
8+
exit 1
9+
fi
10+
11+
echo JOB_NAME = $job
12+
echo NAMESPACE = $ns
13+
14+
15+
kubectl get job -n $ns $job
16+
job_exists=$?
17+
18+
if [ $job_exists -ne 0 ]
19+
then
20+
exit 1
21+
fi
22+
23+
while true;
24+
do
25+
echo "checking for success"
26+
kubectl wait --for=condition=complete -n $ns job/$job --timeout=0s >> /dev/null 2>&1
27+
success=$?
28+
if [ $success -eq 0 ]
29+
then
30+
exit 0;
31+
fi
32+
33+
echo "checking for failure"
34+
kubectl wait --for=condition=failed -n $ns job/$job --timeout=0s >> /dev/null 2>&1
35+
fail=$?
36+
if [ $fail -eq 0 ]
37+
then
38+
exit 1
39+
fi
40+
41+
sleep 5
42+
done

0 commit comments

Comments
 (0)