From fca70628dbd21459bac7aacfef55c6ea836b8704 Mon Sep 17 00:00:00 2001 From: schooltechx Date: Tue, 11 Apr 2023 02:39:38 +0700 Subject: [PATCH] Add super fast deploy script. Build/Cached local. --- .github/workflows/local-build-push.yaml | 79 +++++++++++++++++++++++++ cms/Dockerfile | 2 +- 2 files changed, 80 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/local-build-push.yaml diff --git a/.github/workflows/local-build-push.yaml b/.github/workflows/local-build-push.yaml new file mode 100644 index 0000000..95c4f36 --- /dev/null +++ b/.github/workflows/local-build-push.yaml @@ -0,0 +1,79 @@ + +name: local-build +run-name: local-build ${{ github.actor }} +on: + # push: + # tags: + # - v1.** + # branches: + # - 'main' + # branches: + # - 'release-*' + + # Allow run workflow manually from Action tab + workflow_dispatch: + inputs: + IMAGE_VER: + description: "version for build image" + type: string + +env: + REGISTRY: docker.frappet.com + IMAGE_NAME: demo/qualifying-exam-cms + DEPLOY_HOST: frappet.com + COMPOSE_PATH: /home/frappet/docker/bma-ehr-qualifying-cms + +jobs: + # act workflow_dispatch --reuse -W .github/workflows/local-build-push.yaml --input IMAGE_VER=v0.2.17-dev -s DOCKER_USER=sorawit -s DOCKER_PASS=P@ssword -s SSH_PASSWORD=P@ssw0rd + local-image: + runs-on: ubuntu-latest + steps: + - name: Check out code # checkout only cms is possible but I checkout all + uses: actions/checkout@v3 + - name: Gen Version + id: gen_ver + run: | + IMAGE_VER=${{ github.event.inputs.IMAGE_VER }} + echo "{\"version\":\"$IMAGE_VER\", \"builddate\":\"$(date +"%Y-%m-%d_%T")\",\"ref_name\":\"$GITHUB_REF\" }" > ./cms/src/lib/ver.json + cat ./cms/src/lib/ver.json + echo '::set-output name=image_ver::'$IMAGE_VER + - name: Debug act + if: ${{ env.ACT }} + run: | + echo $GITHUB_REF + echo ${{ steps.gen_ver.outputs.image_ver }} + cat ./cms/src/lib/ver.json + - 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@v4 + with: + context: cms + load: true + cache-from: type=gha + cache-to: type=gha,mode=max + # cache-from: type=local,src=/tmp/.buildx-cache + # cache-to: type=local,dest=/tmp/.buildx-cache-new,mode=max + tags: ${{env.REGISTRY}}/${{env.IMAGE_NAME}}:${{ steps.gen_ver.outputs.image_ver }},${{env.REGISTRY}}/${{env.IMAGE_NAME}}:latest + - name: Push image to registry + run: | + docker push ${{env.REGISTRY}}/${{env.IMAGE_NAME}}:${{ steps.gen_ver.outputs.image_ver }} + docker push ${{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 + diff --git a/cms/Dockerfile b/cms/Dockerfile index f410a49..2eb4cf3 100644 --- a/cms/Dockerfile +++ b/cms/Dockerfile @@ -6,7 +6,7 @@ COPY *.json . COPY *.*s . RUN npm i COPY src ./src -RUN ls +# RUN ls RUN npm run build FROM node:18-alpine WORKDIR /app