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

fix(pre-preview): mount .env file for spx-backend #946

Merged
merged 1 commit into from
Sep 25, 2024
Merged
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
43 changes: 23 additions & 20 deletions scripts/pr-preview.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,6 @@ set -ex

echo "WORKSPACE: ${PWD}"

PREVIEW_URL="http://goplus-builder-pr-${PULL_NUMBER}.goplus-pr-review.svc.jfcs-qa1.local"

echo "VITE_PUBLISH_BASE_URL=${PREVIEW_URL}/" > spx-gui/.env.staging.local

GOPLUS_REGISTRY_REPO=aslan-spock-register.qiniu.io/goplus
CONTAINER_IMAGE="${GOPLUS_REGISTRY_REPO}/goplus-builder-pr:${PULL_NUMBER}-${PULL_PULL_SHA:0:8}"
docker build \
Expand All @@ -27,7 +23,7 @@ docker build \

CURRENT_TIME="$(date "--iso-8601=seconds")"
# generate kubernetes yaml with unique flag for PR
cat > builder.yaml << EOF
cat > goplus-builder.yaml << EOF
apiVersion: apps/v1
kind: Deployment
metadata:
Expand All @@ -37,7 +33,6 @@ metadata:
annotations:
sleepmode.kubefree.com/activity-status: '{"LastActivityTime": "${CURRENT_TIME}"}'
spec:
replicas: 1
selector:
matchLabels:
app: goplus-builder-pr-${PULL_NUMBER}
Expand All @@ -47,11 +42,22 @@ spec:
app: goplus-builder-pr-${PULL_NUMBER}
spec:
containers:
- name: my-container
- name: goplus-builder
image: ${CONTAINER_IMAGE}
ports:
- containerPort: 80
---
volumeMounts:
- name: spx-backend-data
mountPath: /app/.env
subPath: .env
volumes:
- name: spx-backend-data
configMap:
name: spx-backend
items:
- key: .env
path: .env
---
apiVersion: v1
kind: Service
metadata:
Expand All @@ -64,20 +70,17 @@ spec:
selector:
app: goplus-builder-pr-${PULL_NUMBER}
ports:
- protocol: TCP
port: 80
targetPort: 80
type: ClusterIP
- port: 80
EOF

kubectl -n goplus-pr-review apply -f builder.yaml
kubectl -n goplus-pr-review apply -f goplus-builder.yaml
kubectl -n goplus-pr-review get pod

kubectl -n goplus-pr-review get pods

# comment on the PR
message=$'The PR environment is ready, please check the [PR environment]('${PREVIEW_URL}')
PREVIEW_URL="http://goplus-builder-pr-${PULL_NUMBER}.goplus-pr-review.svc.jfcs-qa1.local"
COMMENT=$'
This PR has been deployed to the preview environment. You can explore it using the [preview URL]('${PREVIEW_URL}').

[Attention]: This environment will be automatically cleaned up after a certain period of time., please make sure to test it in time. If you have any questions, please contact the builder team.
> [!WARNING]
> Please note that deployments in the preview environment are temporary and will be automatically cleaned up after a certain period. Make sure to explore it before it is removed. For any questions, contact the Go+ Builder team.
'
gh_comment -org=${REPO_OWNER} -repo=${REPO_NAME} -num=${PULL_NUMBER} -p=${PREVIEW_URL} -b "${message}"

gh_comment -org="${REPO_OWNER}" -repo="${REPO_NAME}" -num="${PULL_NUMBER}" -p="${PREVIEW_URL}" -b "${COMMENT}"
Loading