From c32454dcd5f57e6f54a0fd5cf33887565b193556 Mon Sep 17 00:00:00 2001 From: Serhii Zhylko Date: Fri, 15 Nov 2024 09:31:07 +0100 Subject: [PATCH 1/4] add morphos --- .github/workflows/deploy.dev.yml | 57 ++++++++++++++++++++++++++++++ .github/workflows/deploy_image.yml | 53 --------------------------- .github/workflows/test.yml | 27 -------------- 3 files changed, 57 insertions(+), 80 deletions(-) create mode 100644 .github/workflows/deploy.dev.yml delete mode 100644 .github/workflows/deploy_image.yml delete mode 100644 .github/workflows/test.yml diff --git a/.github/workflows/deploy.dev.yml b/.github/workflows/deploy.dev.yml new file mode 100644 index 0000000..77d9d7e --- /dev/null +++ b/.github/workflows/deploy.dev.yml @@ -0,0 +1,57 @@ +name: "[DEV] - Deploy" + +on: + push: + branches: + - gh_actions + pull_request: + branches: + - dev + types: + - closed + workflow_dispatch: +jobs: + deploy: + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v4 + - name: get-npm-version + id: package-version + run: | + echo "current-version=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT + - id: 'auth' + uses: 'google-github-actions/auth@v2' + with: + credentials_json: ${{secrets.GCP_DEV_CREDENTIALS}} + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + - name: Login to GCR + uses: docker/login-action@v3 + with: + registry: "us.gcr.io" + username: _json_key + password: ${{ secrets.GCP_DEV_CREDENTIALS }} + - name: Build and push + uses: docker/build-push-action@v6 + id: docker_build + env: + DOCKER_BUILD_RECORD_UPLOAD: false + with: + push: true + no-cache: true + provenance: false + tags: us.gcr.io/${{ secrets.GCP_PROJECT_DEV }}/morphos/:commit-${{ steps.package-version.outputs.current-version }} +# - name: Deploy +# shell: bash +# env: +# version: ${{ steps.package-version.outputs.current-version }} +# run: |- +# gcloud run services update morphos \ +# --project=${{ secrets.GCP_PROJECT_DEV }} \ +# --platform=managed \ +# --image="${{steps.docker_build.outputs.metadata && fromJSON(steps.docker_build.outputs.metadata)['image.name'] || steps.package-version.outputs.current-version-register}}" \ +# --labels=commit-sha=$GITHUB_SHA \ +# --region=${{ secrets.REGION }} \ +# --revision-suffix=$(date +%Y%m%dT%H%M%S | tr '[:upper:]' '[:lower:]')-v${version//./-} \ +# --quiet \ No newline at end of file diff --git a/.github/workflows/deploy_image.yml b/.github/workflows/deploy_image.yml deleted file mode 100644 index 83a5d87..0000000 --- a/.github/workflows/deploy_image.yml +++ /dev/null @@ -1,53 +0,0 @@ -name: Deploy Morphos Server Container Image - -on: - push: - tags: - - 'v[0-9]+.[0-9]+.[0-9]+' # Only build on tag with semantic versioning format - -jobs: - push_morphos_image: - runs-on: ubuntu-latest - permissions: - contents: write - packages: write - steps: - - name: Checkout - uses: actions/checkout@v4 - - name: Set up QEMU - uses: docker/setup-qemu-action@v3 - # Script for setting the version without the leading 'v' - - name: Set Versions - uses: actions/github-script@v7 - id: set_version - with: - script: | - // Get the tag - const tag = context.ref.substring(10) - // Replace the tag with one without v - const no_v = tag.replace('v', '') - // Looks for a dash - const dash_index = no_v.lastIndexOf('-') - // If any, removes it, otherwise return the value unchanged - const no_dash = (dash_index > -1) ? no_v.substring(0, dash_index) : no_v - // Set the tag, no-v and no-dash as output variables - core.setOutput('tag', tag) - core.setOutput('no-v', no_v) - core.setOutput('no-dash', no_dash) - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v3 - - name: Login to GitHub Container Registry - uses: docker/login-action@v3 - with: - registry: ghcr.io - username: ${{ github.actor }} - password: ${{ secrets.GITHUB_TOKEN }} - - name: Build and push - uses: docker/build-push-action@v5 - with: - context: . - platforms: linux/amd64,linux/arm64 - push: true - tags: ghcr.io/${{ github.actor }}/morphos-server:latest, ghcr.io/${{ github.actor }}/morphos-server:${{steps.set_version.outputs.no-dash}} - - name: Release - uses: softprops/action-gh-release@v1 diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml deleted file mode 100644 index 69dc616..0000000 --- a/.github/workflows/test.yml +++ /dev/null @@ -1,27 +0,0 @@ -name: Tests - -on: [push] - -jobs: - tests: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - name: Set up Go - uses: actions/setup-go@v4 - with: - go-version: "1.23" - - name: Install linux dependencies - run: | - sudo apt-get update && sudo apt-get upgrade - sudo apt-get -y install libreoffice calibre - - name: Setup ffmpeg - uses: FedericoCarboni/setup-ffmpeg@v3 - id: setup-ffmpeg - with: - ffmpeg-version: 6.1.0 - github-token: ${{ github.server_url == 'https://github.com' && github.token || '' }} - - name: Install Go dependencies - run: go get . - - name: Test - run: go test -v ./... From 04e712301ba6a0f1312b6c1834c66e1248075071 Mon Sep 17 00:00:00 2001 From: Serhii Zhylko Date: Fri, 15 Nov 2024 09:34:08 +0100 Subject: [PATCH 2/4] add morphos --- .github/workflows/deploy.dev.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/deploy.dev.yml b/.github/workflows/deploy.dev.yml index 77d9d7e..f22863d 100644 --- a/.github/workflows/deploy.dev.yml +++ b/.github/workflows/deploy.dev.yml @@ -41,7 +41,7 @@ jobs: push: true no-cache: true provenance: false - tags: us.gcr.io/${{ secrets.GCP_PROJECT_DEV }}/morphos/:commit-${{ steps.package-version.outputs.current-version }} + tags: us.gcr.io/${{ secrets.GCP_PROJECT_DEV }}/vial-dcs-backend/morphos:commit-${{ steps.package-version.outputs.current-version }} # - name: Deploy # shell: bash # env: From cc9735959b22a04c57d13bf7cea016dcf5cd7461 Mon Sep 17 00:00:00 2001 From: Serhii Zhylko Date: Fri, 15 Nov 2024 16:15:31 +0100 Subject: [PATCH 3/4] add morphos --- .github/workflows/deploy.dev.yml | 22 +++++++--------------- Dockerfile | 2 +- 2 files changed, 8 insertions(+), 16 deletions(-) diff --git a/.github/workflows/deploy.dev.yml b/.github/workflows/deploy.dev.yml index f22863d..a750ec1 100644 --- a/.github/workflows/deploy.dev.yml +++ b/.github/workflows/deploy.dev.yml @@ -39,19 +39,11 @@ jobs: DOCKER_BUILD_RECORD_UPLOAD: false with: push: true - no-cache: true + no-cache: false provenance: false - tags: us.gcr.io/${{ secrets.GCP_PROJECT_DEV }}/vial-dcs-backend/morphos:commit-${{ steps.package-version.outputs.current-version }} -# - name: Deploy -# shell: bash -# env: -# version: ${{ steps.package-version.outputs.current-version }} -# run: |- -# gcloud run services update morphos \ -# --project=${{ secrets.GCP_PROJECT_DEV }} \ -# --platform=managed \ -# --image="${{steps.docker_build.outputs.metadata && fromJSON(steps.docker_build.outputs.metadata)['image.name'] || steps.package-version.outputs.current-version-register}}" \ -# --labels=commit-sha=$GITHUB_SHA \ -# --region=${{ secrets.REGION }} \ -# --revision-suffix=$(date +%Y%m%dT%H%M%S | tr '[:upper:]' '[:lower:]')-v${version//./-} \ -# --quiet \ No newline at end of file + tags: us.gcr.io/${{secrets.GCP_PROJECT_DEV}}/vial-dcs-backend/morphos:commit-${{ steps.package-version.outputs.current-version }} + - id: 'deploy' + uses: 'google-github-actions/deploy-cloudrun@v2' + with: + service: "morphos" + image: "${{fromJSON(steps.docker_build.outputs.metadata)['image.name']}}" \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 777fab1..a3f1c07 100644 --- a/Dockerfile +++ b/Dockerfile @@ -33,7 +33,7 @@ RUN apt-get update \ COPY --from=builder /app/morphos /bin/morphos COPY --from=builder /usr/share/fonts /usr/share/fonts -ENV FONTCONFIG_PATH /usr/share/fonts +ENV FONTCONFIG_PATH=/usr/share/fonts # Use morphos as user RUN useradd -m morphos From 8358c97aafc69b4266b0c7903b058542f9fa76ea Mon Sep 17 00:00:00 2001 From: Serhii Zhylko Date: Fri, 15 Nov 2024 17:31:30 +0100 Subject: [PATCH 4/4] fix --- .github/workflows/deploy.dev.yml | 3 -- .github/workflows/deploy.prod.yml | 46 ++++++++++++++++++++++++++++++ .github/workflows/deploy.stage.yml | 46 ++++++++++++++++++++++++++++++ 3 files changed, 92 insertions(+), 3 deletions(-) create mode 100644 .github/workflows/deploy.prod.yml create mode 100644 .github/workflows/deploy.stage.yml diff --git a/.github/workflows/deploy.dev.yml b/.github/workflows/deploy.dev.yml index a750ec1..e597fd9 100644 --- a/.github/workflows/deploy.dev.yml +++ b/.github/workflows/deploy.dev.yml @@ -1,9 +1,6 @@ name: "[DEV] - Deploy" on: - push: - branches: - - gh_actions pull_request: branches: - dev diff --git a/.github/workflows/deploy.prod.yml b/.github/workflows/deploy.prod.yml new file mode 100644 index 0000000..52319d6 --- /dev/null +++ b/.github/workflows/deploy.prod.yml @@ -0,0 +1,46 @@ +name: "[PROD] - Deploy" + +on: + pull_request: + branches: + - main + types: + - closed + workflow_dispatch: +jobs: + deploy: + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v4 + - name: get-npm-version + id: package-version + run: | + echo "current-version=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT + - id: 'auth' + uses: 'google-github-actions/auth@v2' + with: + credentials_json: ${{secrets.GCP_PROD_CREDENTIALS}} + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + - name: Login to GCR + uses: docker/login-action@v3 + with: + registry: "us.gcr.io" + username: _json_key + password: ${{ secrets.GCP_PROD_CREDENTIALS }} + - name: Build and push + uses: docker/build-push-action@v6 + id: docker_build + env: + DOCKER_BUILD_RECORD_UPLOAD: false + with: + push: true + no-cache: false + provenance: false + tags: us.gcr.io/${{secrets.GCP_PROJECT_PROD}}/vial-dcs-backend/morphos:commit-${{ steps.package-version.outputs.current-version }} + - id: 'deploy' + uses: 'google-github-actions/deploy-cloudrun@v2' + with: + service: "morphos" + image: "${{fromJSON(steps.docker_build.outputs.metadata)['image.name']}}" \ No newline at end of file diff --git a/.github/workflows/deploy.stage.yml b/.github/workflows/deploy.stage.yml new file mode 100644 index 0000000..eab5f5d --- /dev/null +++ b/.github/workflows/deploy.stage.yml @@ -0,0 +1,46 @@ +name: "[STAGE] - Deploy" + +on: + pull_request: + branches: + - stage + types: + - closed + workflow_dispatch: +jobs: + deploy: + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v4 + - name: get-npm-version + id: package-version + run: | + echo "current-version=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT + - id: 'auth' + uses: 'google-github-actions/auth@v2' + with: + credentials_json: ${{secrets.GCP_STAGING_CREDENTIALS}} + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + - name: Login to GCR + uses: docker/login-action@v3 + with: + registry: "us.gcr.io" + username: _json_key + password: ${{ secrets.GCP_STAGING_CREDENTIALS }} + - name: Build and push + uses: docker/build-push-action@v6 + id: docker_build + env: + DOCKER_BUILD_RECORD_UPLOAD: false + with: + push: true + no-cache: false + provenance: false + tags: us.gcr.io/${{secrets.GCP_PROJECT_STAGING}}/vial-dcs-backend/morphos:commit-${{ steps.package-version.outputs.current-version }} + - id: 'deploy' + uses: 'google-github-actions/deploy-cloudrun@v2' + with: + service: "morphos" + image: "${{fromJSON(steps.docker_build.outputs.metadata)['image.name']}}" \ No newline at end of file