Skip to content
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
51 changes: 51 additions & 0 deletions .github/scripts/deploy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#!/bin/bash
set -e

echo "${CONFIG_JSON}" > deploy/${ENV}/config.json

sed -i "s#{{.ALIYUN_ACCESS_KEY}}#${ALIYUN_ACCESS_KEY}#g" deploy/${ENV}/config.json
sed -i "s#{{.ALIYUN_ACCESS_SECRET}}#${ALIYUN_ACCESS_SECRET}#g" deploy/${ENV}/config.json
sed -i "s#{{.CAPTCHA_API_KEY}}#${CAPTCHA_API_KEY}#g" deploy/${ENV}/config.json
sed -i "s#{{.CAPTCHA_TMP_PROXY}}#${CAPTCHA_TMP_PROXY}#g" deploy/${ENV}/config.json

echo "${ALICLOUD_ACK_CLUSTER_CONFIG}" > deploy/${ENV}/kubeconfig.yaml

cp deploy/${ENV}/config.json configs/browser/config.json
cp deploy/${ENV}/kubeconfig.yaml configs/browser/kubeconfig.yaml

docker buildx build \
--build-arg SSH_PRIVATE_KEY="${SSH_PRIVATE_KEY}" \
--build-arg ENV="${ENV}" \
--push \
-f Dockerfile -t ${IMAGE_VERSION} .

sed -i "s#{{.ENV}}#${ENV}#g" deploy/${ENV}/deployment.yaml
sed -i "s#{{.IMAGE_VERSION}}#${IMAGE_VERSION}#g" deploy/${ENV}/deployment.yaml
sed -i "s#{{.APP_NAME}}#${APP_NAME}#g" deploy/${ENV}/deployment.yaml

sed -i "s#{{.ENV}}#${ENV}#g" deploy/${ENV}/service.yaml
sed -i "s#{{.APP_NAME}}#${APP_NAME}#g" deploy/${ENV}/service.yaml

mkdir -p ~/.kube
echo "${ALICLOUD_ACK_CLUSTER_CONFIG}" > ~/.kube/config
export KUBECONFIG=~/.kube/config

if kubectl get secret acr-secret -n ${ENV} &> /dev/null; then
echo "Secret acr-secret already exists in the default namespace. Skipping creation."
else
kubectl create secret docker-registry acr-secret \
--docker-server=${ALICLOUD_ACR_REGISTRY} \
--docker-username=${ALICLOUD_USERNAME} \
--docker-password=${ALICLOUD_PASSWORD} \
--namespace=${ENV}
fi

kubectl apply -f deploy/${ENV}/deployment.yaml
kubectl apply -f deploy/${ENV}/service.yaml

echo "deployments:"
kubectl get deployments -n ${ENV}
echo "pods:"
kubectl get pods -n ${ENV}
echo "services:"
kubectl get services -n ${ENV}
61 changes: 61 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
name: Deploy
env:
APP_NAME: browser
run-name: Deploy [${{ github.ref }} branch] to [${{ inputs.deploy_env }} env] by ${{ github.actor }}

#on:
# push:
# branches:
# - main
on:
workflow_dispatch:
inputs:
deploy_env:
type: choice
description: which env to deploy
options:
- prod
- dev

jobs:
build-and-deploy:
runs-on: ubuntu-latest

steps:
- name: echo version
run: echo "${{ inputs.deploy_env }}"

- name: Checkout code
uses: actions/checkout@v3

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2

- name: Login to ACR
uses: docker/login-action@v2
with:
registry: ${{ secrets.ALICLOUD_ACR_REGISTRY }}
username: ${{ secrets.ALICLOUD_USERNAME }}
password: ${{ secrets.ALICLOUD_PASSWORD }}

- name: Make shell file executable
run: chmod +x ./.github/scripts/deploy.sh

- name: Build and Push Docker image and Deploy to ACK
shell: bash
env:
ENV: ${{ inputs.deploy_env }}
APP_NAME: ${{ env.APP_NAME }}
ALICLOUD_ACR_REGISTRY: ${{ secrets.ALICLOUD_ACR_REGISTRY }}
ALICLOUD_ACR_NAMESPACE: ${{ secrets.ALICLOUD_ACR_NAMESPACE }}
ALICLOUD_ACR_REPOSITORY: ${{ secrets.ALICLOUD_ACR_REPOSITORY }}
ALICLOUD_USERNAME: ${{ secrets.ALICLOUD_USERNAME }}
ALICLOUD_PASSWORD: ${{ secrets.ALICLOUD_PASSWORD }}
ALICLOUD_ACK_CLUSTER_CONFIG: ${{ secrets.ALICLOUD_ACK_CLUSTER_CONFIG }}
IMAGE_VERSION: ${{ secrets.ALICLOUD_ACR_REGISTRY }}/${{ secrets.ALICLOUD_ACR_NAMESPACE }}/${{ secrets.ALICLOUD_ACR_REPOSITORY }}:${{ env.APP_NAME }}-${{ inputs.deploy_env }}-${{ github.sha }}
ALIYUN_ACCESS_KEY: ${{ secrets.ALIYUN_ACCESS_KEY }}
ALIYUN_ACCESS_SECRET: ${{ secrets.ALIYUN_ACCESS_SECRET }}
CAPTCHA_API_KEY: ${{ secrets.CAPTCHA_API_KEY }}
CAPTCHA_TMP_PROXY: ${{ secrets.CAPTCHA_TMP_PROXY }}
CONFIG_JSON: ${{ secrets.CONFIG_JSON }}
run: ./.github/scripts/deploy.sh
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,7 @@ dist
.DS_Store
*.webm

config.json
browser/config.json
configs/browser/config.json
configs/proxy/*
configs/profile/*

Expand Down
8 changes: 4 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ COPY . .
RUN npm install -g pnpm
RUN npx playwright install-deps
RUN wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add - \
&& echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google.list \
&& apt-get update \
&& apt-get install -y google-chrome-stable
&& echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google.list \
&& apt-get update \
&& apt-get install -y google-chrome-stable
RUN cd browser && sh build_worklets.sh && pnpm install && npm run build:api
RUN apt-get install -y net-tools
RUN apt-get install -y nginx
Expand All @@ -19,7 +19,7 @@ RUN mkdir -p /etc/nginx/stream-conf.d
RUN bash -c 'for i in {0..199}; do \
src=$((15001+i)); dst=$((9401+i)); \
echo "server { listen $src; proxy_pass 127.0.0.1:$dst; }" >> /etc/nginx/stream-conf.d/port_forward.conf; \
done'
done'

WORKDIR /app/browser

Expand Down
28 changes: 28 additions & 0 deletions deploy/prod/auto_scaling.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
name: browser-hpa
namespace: prod
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: browser
minReplicas: 1
maxReplicas: 10
metrics:
- type: Resource
resource:
name: cpu
target:
type: Utilization
averageUtilization: 70
- type: Resource
resource:
name: memory
target:
type: Utilization
averageUtilization: 70
behavior:
scaleDown:
stabilizationWindowSeconds: 900
Empty file added deploy/prod/config.json
Empty file.
34 changes: 34 additions & 0 deletions deploy/prod/deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{.APP_NAME}}
namespace: {{.ENV}}
labels:
app: {{.APP_NAME}}
spec:
replicas: 1
selector:
matchLabels:
app: {{.APP_NAME}}
template:
metadata:
labels:
app: {{.APP_NAME}}
spec:
hostNetwork: true
containers:
- name: {{.APP_NAME}}-container
image: {{.IMAGE_VERSION}}
ports:
- name: http
containerPort: 13100
protocol: TCP
resources:
requests:
cpu: "1000m"
memory: "2Gi"
limits:
cpu: "4000m"
memory: "4Gi"
imagePullSecrets:
- name: acr-secret
Empty file added deploy/prod/kubeconfig.yaml
Empty file.
13 changes: 13 additions & 0 deletions deploy/prod/service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
apiVersion: v1
kind: Service
metadata:
name: {{.APP_NAME}}
spec:
selector:
app: {{.APP_NAME}}
ports:
- name: http
protocol: TCP
port: 13100
targetPort: 13100
type: ClusterIP
Loading