From 4be268d5628d9e6a76882dc0affd79cb7e8678fb Mon Sep 17 00:00:00 2001 From: Kittapath Date: Thu, 17 Aug 2023 06:19:49 +0700 Subject: [PATCH] set file deploy --- .env.production | 1 + .github/workflows/release.yaml | 86 ++++++++++++++++++++++++++++++++++ Dockerfile | 21 +++++++++ entrypoint.sh | 16 +++++++ nginx.conf | 30 ++++++++++++ src/api/index.ts | 3 +- 6 files changed, 156 insertions(+), 1 deletion(-) create mode 100644 .env.production create mode 100644 .github/workflows/release.yaml create mode 100644 Dockerfile create mode 100644 entrypoint.sh create mode 100644 nginx.conf diff --git a/.env.production b/.env.production new file mode 100644 index 0000000..ff715a2 --- /dev/null +++ b/.env.production @@ -0,0 +1 @@ +VITE_API_URI_CONFIG=VITE_API_URI_CONFIG \ No newline at end of file diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml new file mode 100644 index 0000000..56f0b9a --- /dev/null +++ b/.github/workflows/release.yaml @@ -0,0 +1,86 @@ +name: release-dev +run-name: release-dev ${{ github.actor }} +on: + # push: + # tags: + # - 'v[0-9]+.[0-9]+.[0-9]+' + # tags-ignore: + # - '2.*' + # Allow run workflow manually from Action tab + workflow_dispatch: +env: + REGISTRY: docker.frappet.com + IMAGE_NAME: ehr/bma-ehr-user + DEPLOY_HOST: frappet.com + COMPOSE_PATH: /home/frappet/docker/bma-ehr-user + TOKEN_LINE: uxuK5hDzS2DsoC5piJBrWRLiz8GgY7iMZZldOWsDDF0 + +jobs: + # act workflow_dispatch -W .github/workflows/release.yaml --input IMAGE_VER=test-v6.1 -s DOCKER_USER=sorawit -s DOCKER_PASS=P@ssword -s SSH_PASSWORD=P@ssw0rd + release-dev: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + # skip Set up QEMU because it fail on act and container + - name: Gen Version + id: gen_ver + run: | + if [[ $GITHUB_REF == 'refs/tags/'* ]]; then + IMAGE_VER='${GITHUB_REF/refs\/tags\//}' + else + IMAGE_VER=${{ github.event.inputs.IMAGE_VER }} + fi + if [[ $IMAGE_VER == '' ]]; then + IMAGE_VER='test-vBeta' + fi + echo '::set-output name=image_ver::'$IMAGE_VER + - name: Test Version + run: | + echo $GITHUB_REF + echo ${{ steps.gen_ver.outputs.image_ver }} + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + - name: Login in to registry + uses: docker/login-action@v2 + with: + registry: ${{env.REGISTRY}} + username: ${{secrets.DOCKER_USER}} + password: ${{secrets.DOCKER_PASS}} + - name: Build and load local docker image + uses: docker/build-push-action@v3 + with: + context: . + platforms: linux/amd64 + push: true + tags: ${{env.REGISTRY}}/${{env.IMAGE_NAME}}:${{ steps.gen_ver.outputs.image_ver }},${{env.REGISTRY}}/${{env.IMAGE_NAME}}:latest + + - name: Reload docker compose + uses: appleboy/ssh-action@v0.1.8 + with: + host: ${{env.DEPLOY_HOST}} + username: frappet + password: ${{ secrets.SSH_PASSWORD }} + port: 22 + script: | + cd "${{env.COMPOSE_PATH}}" + docker-compose pull + docker-compose up -d + echo "${{ steps.gen_ver.outputs.image_ver }}"> success + # - uses: snow-actions/line-notify@v1.1.0 + # if: success() + # with: + # access_token: ${{ env.TOKEN_LINE }} + # message: | + # -Success✅✅✅ + # Image: ${{env.IMAGE_NAME}} + # Version: ${{ github.event.inputs.IMAGE_VER }} + # By: ${{secrets.DOCKER_USER}} + # - uses: snow-actions/line-notify@v1.1.0 + # if: failure() + # with: + # access_token: ${{ env.TOKEN_LINE }} + # message: | + # -Failure❌❌❌ + # Image: ${{env.IMAGE_NAME}} + # Version: ${{ github.event.inputs.IMAGE_VER }} + # By: ${{secrets.DOCKER_USER}} diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..a6b08ee --- /dev/null +++ b/Dockerfile @@ -0,0 +1,21 @@ +# docker build . -t docker.frappet.com/demo/fe:latest +FROM node:latest as build-stage +WORKDIR /app +COPY package*.json ./ +RUN npm install +COPY ./ . + +RUN npm run build + +FROM nginx as production-stage + +RUN mkdir /app +COPY --from=build-stage /app/dist /app +COPY nginx.conf /etc/nginx/nginx.conf + +COPY entrypoint.sh /usr/local/bin/entrypoint.sh +RUN chmod u+x /usr/local/bin/entrypoint.sh + + +ENTRYPOINT ["/usr/local/bin/entrypoint.sh"] +CMD ["nginx", "-g", "daemon off;"] diff --git a/entrypoint.sh b/entrypoint.sh new file mode 100644 index 0000000..38b8d06 --- /dev/null +++ b/entrypoint.sh @@ -0,0 +1,16 @@ +#!/bin/sh + +ROOT_DIR=/app + +# Replace env vars in JavaScript files +echo "Replacing env constants in JS" +for file in $ROOT_DIR/assets/app.*.js* $ROOT_DIR/js/app.*.js* $ROOT_DIR/index.html $ROOT_DIR/precache-manifest*.js; +do + echo "Processing $file ..."; + + sed -i 's|VITE_API_URI_CONFIG|'${VITE_API_URI_CONFIG}'|g' $file + +done + +echo "Starting Nginx" +nginx -g 'daemon off;' diff --git a/nginx.conf b/nginx.conf new file mode 100644 index 0000000..6f61d6c --- /dev/null +++ b/nginx.conf @@ -0,0 +1,30 @@ +user nginx; +worker_processes 1; +error_log /var/log/nginx/error.log warn; +pid /var/run/nginx.pid; +events { + worker_connections 1024; +} +http { + include /etc/nginx/mime.types; + default_type application/octet-stream; + log_format main '$remote_addr - $remote_user [$time_local] "$request" ' + '$status $body_bytes_sent "$http_referer" ' + '"$http_user_agent" "$http_x_forwarded_for"'; + access_log /var/log/nginx/access.log main; + sendfile on; + keepalive_timeout 65; + server { + listen 80; + server_name localhost; + location / { + root /app; + index index.html; + try_files $uri $uri/ /index.html; + } + error_page 500 502 503 504 /50x.html; + location = /50x.html { + root /usr/share/nginx/html; + } + } +} diff --git a/src/api/index.ts b/src/api/index.ts index 4552074..25db145 100644 --- a/src/api/index.ts +++ b/src/api/index.ts @@ -2,6 +2,7 @@ import { ref } from "vue" const env = ref(process.env.NODE_ENV || "development") +export const apiUrlConfig = import.meta.env.VITE_API_URI_CONFIG // if (process.env.VUE_APP_TEST) { // env = "test"; // } @@ -17,7 +18,7 @@ const config = ref({ MEET_URI: "meet.frappet.com", }, production: { - API_URI: `${window.location.protocol}//${window.location.host}/api/v1`, + API_URI: apiUrlConfig, API_URI_ORG_TREE: "https://s3cluster.frappet.com/bma-ehr-fpt/organization/strueture/tree_20230707_115124.json", MEET_URI: "meet.frappet.com", },