diff --git a/.github/actions/build-docker-image/action.yml b/.github/actions/build-docker-image/action.yml new file mode 100644 index 0000000000..5f434a0950 --- /dev/null +++ b/.github/actions/build-docker-image/action.yml @@ -0,0 +1,67 @@ +name: Build docker image +description: Build and push the Documenso Docker image to a registry + +inputs: + registry_url: + description: Container registry hostname + required: false + default: ghcr.io + registry_username: + description: Registry username + required: true + registry_password: + description: Registry password or token + required: true + docker_image: + description: Repository/image name + required: true + docker_file: + description: Dockerfile path + required: false + default: ./docker/Dockerfile + docker_tag: + description: Docker tag to publish + required: false + default: latest + next_private_telemetry_key: + description: Optional telemetry key passed at build time + required: false + default: '' + next_private_telemetry_host: + description: Optional telemetry host passed at build time + required: false + default: '' + +runs: + using: composite + steps: + - name: Login to registry + uses: docker/login-action@v3 + with: + registry: ${{ inputs.registry_url }} + username: ${{ inputs.registry_username }} + password: ${{ inputs.registry_password }} + + - name: Normalize image name + id: image + shell: bash + run: echo "name=$(echo '${{ inputs.docker_image }}' | tr '[:upper:]' '[:lower:]')" >> "$GITHUB_OUTPUT" + + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Build and push image + uses: docker/build-push-action@v6 + with: + context: . + file: ${{ inputs.docker_file }} + push: true + tags: ${{ inputs.registry_url }}/${{ steps.image.outputs.name }}:${{ inputs.docker_tag }} + cache-from: type=registry,ref=${{ inputs.registry_url }}/${{ steps.image.outputs.name }}:${{ inputs.docker_tag }}-cache + cache-to: type=registry,ref=${{ inputs.registry_url }}/${{ steps.image.outputs.name }}:${{ inputs.docker_tag }}-cache,mode=max + build-args: | + NEXT_PRIVATE_TELEMETRY_KEY=${{ inputs.next_private_telemetry_key }} + NEXT_PRIVATE_TELEMETRY_HOST=${{ inputs.next_private_telemetry_host }} diff --git a/.github/workflows/production-release.yml b/.github/workflows/production-release.yml new file mode 100644 index 0000000000..b7685a4122 --- /dev/null +++ b/.github/workflows/production-release.yml @@ -0,0 +1,64 @@ +name: Deploy Production + +env: + ENVIRONMENT: 'production' + IMAGE_NAME: ${{ github.repository }} + DOCKER_TAG: 'latest' + +on: + push: + tags: + - 'v*' + branches: + - master + - main + workflow_dispatch: + +permissions: + contents: read + packages: write + +concurrency: + group: production-release-${{ github.ref }}-1 + cancel-in-progress: true + +jobs: + docker-build-production: + name: Build Latest Image + if: github.ref_type == 'branch' + runs-on: ubuntu-latest + environment: + name: 'production' + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Build production image + uses: ./.github/actions/build-docker-image + with: + registry_username: ${{ github.actor }} + registry_password: ${{ secrets.GITHUB_TOKEN }} + docker_image: ${{ env.IMAGE_NAME }} + docker_tag: ${{ env.DOCKER_TAG }} + next_private_telemetry_key: ${{ secrets.NEXT_PRIVATE_TELEMETRY_KEY }} + next_private_telemetry_host: ${{ secrets.NEXT_PRIVATE_TELEMETRY_HOST }} + + docker-build-tag: + name: Build tag image + if: startsWith(github.ref, 'refs/tags/v') + runs-on: ubuntu-latest + environment: + name: 'production' + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Build tagged image + uses: ./.github/actions/build-docker-image + with: + registry_username: ${{ github.actor }} + registry_password: ${{ secrets.GITHUB_TOKEN }} + docker_image: ${{ env.IMAGE_NAME }} + docker_tag: ${{ github.ref_name }} + next_private_telemetry_key: ${{ secrets.NEXT_PRIVATE_TELEMETRY_KEY }} + next_private_telemetry_host: ${{ secrets.NEXT_PRIVATE_TELEMETRY_HOST }} diff --git a/.github/workflows/staging-release.yml b/.github/workflows/staging-release.yml new file mode 100644 index 0000000000..fcb068dc9b --- /dev/null +++ b/.github/workflows/staging-release.yml @@ -0,0 +1,40 @@ +name: Deploy Staging + +env: + ENVIRONMENT: 'staging' + IMAGE_NAME: ${{ github.repository }} + +on: + push: + branches: + - staging + - staging-* + workflow_dispatch: + +permissions: + contents: read + packages: write + +concurrency: + group: staging-release-${{ github.ref }}-1 + cancel-in-progress: true + +jobs: + docker-build-staging: + name: Build Staging Image + runs-on: ubuntu-latest + environment: + name: 'staging' + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Build staging image + uses: ./.github/actions/build-docker-image + with: + registry_username: ${{ github.actor }} + registry_password: ${{ secrets.GITHUB_TOKEN }} + docker_image: ${{ env.IMAGE_NAME }} + docker_tag: ${{ env.ENVIRONMENT }} + next_private_telemetry_key: ${{ secrets.NEXT_PRIVATE_TELEMETRY_KEY }} + next_private_telemetry_host: ${{ secrets.NEXT_PRIVATE_TELEMETRY_HOST }}