From 302ee1dd3b60b00886a161b23a5f028d14bb0b5e Mon Sep 17 00:00:00 2001 From: Suphonchai Phoonsawat Date: Fri, 21 Apr 2023 10:45:52 +0700 Subject: [PATCH] add github action and dockerfile --- .github/workflows/build-local.yaml | 46 ++++++++++++++++++++ .github/workflows/release.yaml | 67 ++++++++++++++++++++++++++++++ BMA.EHR.Report.Service.csproj | 7 ++++ Dockerfile | 8 ++-- 4 files changed, 125 insertions(+), 3 deletions(-) create mode 100644 .github/workflows/build-local.yaml create mode 100644 .github/workflows/release.yaml diff --git a/.github/workflows/build-local.yaml b/.github/workflows/build-local.yaml new file mode 100644 index 0000000..3a06de7 --- /dev/null +++ b/.github/workflows/build-local.yaml @@ -0,0 +1,46 @@ +# 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-metadata-service +jobs: + # act workflow_dispatch -W .github/workflows/build-local.yaml --input IMAGE_VER=test-v6.1 + 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: 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 + 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 0000000..7a8f4ff --- /dev/null +++ b/.github/workflows/release.yaml @@ -0,0 +1,67 @@ +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-report-service + DEPLOY_HOST: frappet.com + COMPOSE_PATH: /home/frappet/docker/bma-ehr-report + +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 \ No newline at end of file diff --git a/BMA.EHR.Report.Service.csproj b/BMA.EHR.Report.Service.csproj index 598d881..1473796 100644 --- a/BMA.EHR.Report.Service.csproj +++ b/BMA.EHR.Report.Service.csproj @@ -18,6 +18,13 @@ 1701;1702;1591;0436; + + + + + + + diff --git a/Dockerfile b/Dockerfile index 110eaa3..fb65129 100644 --- a/Dockerfile +++ b/Dockerfile @@ -7,10 +7,12 @@ EXPOSE 443 FROM mcr.microsoft.com/dotnet/sdk:7.0 AS build WORKDIR /src -COPY ["BMA.EHR.Report.Service/BMA.EHR.Report.Service.csproj", "BMA.EHR.Report.Service/"] -RUN dotnet restore "BMA.EHR.Report.Service/BMA.EHR.Report.Service.csproj" +COPY Components ./Components +COPY ["nuget.config", "."] +COPY ["BMA.EHR.Report.Service.csproj", "."] +RUN dotnet restore "./BMA.EHR.Report.Service.csproj" COPY . . -WORKDIR "/src/BMA.EHR.Report.Service" +WORKDIR "/src/." RUN dotnet build "BMA.EHR.Report.Service.csproj" -c Release -o /app/build FROM build AS publish