Skip to content

Commit

Permalink
fix: cicd优化
Browse files Browse the repository at this point in the history
  • Loading branch information
debaofu committed Sep 10, 2024
1 parent e8f5533 commit c786180
Show file tree
Hide file tree
Showing 3 changed files with 114 additions and 1 deletion.
3 changes: 2 additions & 1 deletion .github/workflows/docker-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ jobs:
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache-new
build-args: SENTRY_AUTH_TOKEN=${{ secrets.SENTRY_AUTH_TOKEN }}

- name: Move cache
run: |
Expand All @@ -93,4 +94,4 @@ jobs:
# private ssh key registered on the server
PRIVATE_SSH_KEY: ${{ secrets.SERVER_KEY }}
# command to be executed
COMMAND: cd /project/docker-compose && ./run.sh
COMMAND: cd /root && ./run.sh
32 changes: 32 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
FROM gplane/pnpm:8.4.0 as builder
ARG SENTRY_AUTH_TOKEN

WORKDIR /data/web

COPY pnpm-lock.yaml .
COPY package.json .

RUN pnpm install

COPY . .
RUN pnpm run build

FROM nginx:alpine as nginx

RUN cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime \
&& echo "Asia/Shanghai" > /etc/timezone

WORKDIR /data/web

RUN mkdir -p /app/www

COPY --from=builder /data/web/dist /app/www

EXPOSE 80
EXPOSE 443

RUN rm -rf /etc/nginx/conf.d/default.conf
COPY ./nginx/config.sh /root
RUN chmod +x /root/config.sh

CMD ["/root/config.sh"]
80 changes: 80 additions & 0 deletions nginx/config.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
#! /bin/sh -e

echo "setting environment config"

cat >> /etc/nginx/conf.d/default.conf <<EOF
map \$http_upgrade \$connection_upgrade {
default upgrade;
'' close;
}
server {
listen 80;
gzip on;
gzip_min_length 1k;
gzip_buffers 4 16k;
#gzip_http_version 1.0;
gzip_comp_level 2;
gzip_types text/plain application/javascript application/x-javascript text/css application/xml text/javascript application/x-httpd-php image/jpeg image/gif image/png;
gzip_vary off;
gzip_disable "MSIE [1-6].";
proxy_read_timeout 600;
location / {
add_header Access-Control-Allow-Origin *;
add_header Access-Control-Allow-Methods 'GET, POST, OPTIONS';
add_header Access-Control-Allow-Headers 'DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Authorization';
if (\$request_filename ~* .*\.(?:htm|html)$)
{
add_header Cache-Control "private, no-store, no-cache, must-revalidate, proxy-revalidate";
}
root /app/www/;
index index.html;
try_files \$uri \$uri /index.html;
client_max_body_size 500m;
}
location ~* \.js$ {
root /app/www/;
try_files \$uri =404;
}
location ~* \.css$ {
root /app/www/;
try_files \$uri =404;
}
location /api {
proxy_pass $SERVER_URL;
proxy_set_header Host \$host;
proxy_set_header X-Real-IP \$remote_addr;
proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;
}
location /file/ {
proxy_pass $FILE_URL;
proxy_set_header Host \$host;
proxy_set_header X-Real-IP \$remote_addr;
proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;
}
location /ws/ {
proxy_pass $SERVER_URL;
proxy_http_version 1.1;
proxy_set_header Upgrade \$http_upgrade;
proxy_set_header Connection \$connection_upgrade;
proxy_set_header Host \$host;
proxy_set_header X-Real-IP \$remote_addr;
proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;
proxy_set_header REMOTE-HOST \$remote_addr;
}
}
EOF

echo "starting web server"

nginx -g 'daemon off;'

0 comments on commit c786180

Please sign in to comment.