From 1ce8f35aff809097611e969b793f2fe791de192b Mon Sep 17 00:00:00 2001 From: Kittapath Date: Tue, 12 Sep 2023 09:01:03 +0700 Subject: [PATCH] build image --- .env.production | 4 ++ .github/workflows/build-local.yaml | 39 ++++++++++++++ .github/workflows/release.yaml | 86 ++++++++++++++++++++++++++++++ Dockerfile | 6 +-- package.json | 2 +- vite.config.ts | 40 +++++++------- 6 files changed, 153 insertions(+), 24 deletions(-) create mode 100644 .env.production create mode 100644 .github/workflows/build-local.yaml create mode 100644 .github/workflows/release.yaml diff --git a/.env.production b/.env.production new file mode 100644 index 00000000..9fa54e36 --- /dev/null +++ b/.env.production @@ -0,0 +1,4 @@ +VITE_COMPETITIVE_EXAM_PANEL=VITE_COMPETITIVE_EXAM_PANEL +VITE_QUALIFY_DISABLE_EMAM_PANEL=VITE_QUALIFY_DISABLE_EMAM_PANEL +VITE_QUALIFY_EXAM_PANEL=VITE_QUALIFY_EXAM_PANEL +VITE_S3CLUSTER_PUBLIC_URL=VITE_S3CLUSTER_PUBLIC_URL \ No newline at end of file diff --git a/.github/workflows/build-local.yaml b/.github/workflows/build-local.yaml new file mode 100644 index 00000000..b7dc9b1a --- /dev/null +++ b/.github/workflows/build-local.yaml @@ -0,0 +1,39 @@ +# use for local build with act +name: build-local +run-name: build-local ${{ github.actor }} +on: + workflow_dispatch: +env: + REGISTRY: docker.frappet.com + IMAGE_NAME: demo/bma-ehr-manual +jobs: + # act workflow_dispatch -W .github/workflows/build-local.yaml --input IMAGE_VER=test-v1 + build-local: + 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: Build and load local docker image + uses: docker/build-push-action@v3 + with: + context: . + platforms: linux/amd64 + load: true + tags: ${{env.REGISTRY}}/${{env.IMAGE_NAME}}:${{ steps.gen_ver.outputs.image_ver }},${{env.REGISTRY}}/${{env.IMAGE_NAME}}:latest diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml new file mode 100644 index 00000000..33aa1904 --- /dev/null +++ b/.github/workflows/release.yaml @@ -0,0 +1,86 @@ +name: release-test +run-name: release-test ${{ 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-manual + DEPLOY_HOST: frappet.com + COMPOSE_PATH: /home/frappet/docker/bma-ehr-manual + TOKEN_LINE: uxuK5hDzS2DsoC5piJBrWRLiz8GgY7iMZZldOWsDDF0 +jobs: + # act workflow_dispatch -W .github/workflows/release.yaml --input IMAGE_VER=test-v1 -s DOCKER_USER=sorawit -s DOCKER_PASS=P@ssword -s SSH_PASSWORD=P@ssw0rd + release-test: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + # skip Set up QEMU because it fail on act and container + # Gen Version try to get version from tag or inut + - 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: Check 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 push 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: Remote Deployment + 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 index a6b08ee8..653a338e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -13,9 +13,9 @@ 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 +# COPY entrypoint.sh /usr/local/bin/entrypoint.sh +# RUN chmod u+x /usr/local/bin/entrypoint.sh -ENTRYPOINT ["/usr/local/bin/entrypoint.sh"] +# ENTRYPOINT ["/usr/local/bin/entrypoint.sh"] CMD ["nginx", "-g", "daemon off;"] diff --git a/package.json b/package.json index 96bfba59..c5ea1cfb 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,7 @@ "private": true, "scripts": { "dev": "vite", - "build": "run-p build-only", + "build": "run-p ", "preview": "vite preview", "test:unit": "vitest --environment jsdom --root src/", "test:e2e": "start-server-and-test preview :4173 'cypress run --e2e'", diff --git a/vite.config.ts b/vite.config.ts index 9393aa96..614aa1ba 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -7,24 +7,24 @@ import { quasar, transformAssetUrls } from "@quasar/vite-plugin" // https://vitejs.dev/config/ export default defineConfig({ - plugins: [ - vue({ - template: { transformAssetUrls }, - }), - quasar({ - sassVariables: "src/style/quasar-variables.sass", - }), - vueJsx(), - ], - resolve: { - alias: { - "@": fileURLToPath(new URL("./src", import.meta.url)), - }, - }, - build: { - target: "esnext", - }, - server: { - port: 3006, - }, + plugins: [ + vue({ + template: { transformAssetUrls }, + }), + quasar({ + sassVariables: "src/style/quasar-variables.sass", + }), + vueJsx(), + ], + resolve: { + alias: { + "@": fileURLToPath(new URL("./src", import.meta.url)), + }, + }, + build: { + target: "esnext", + }, + server: { + port: 3008, + }, })