From 7b76ad1787275581511677a09558abfb87df91be Mon Sep 17 00:00:00 2001 From: Bohdan Shulha Date: Tue, 2 Jul 2024 23:10:50 +0200 Subject: [PATCH] chore: #30 pack server into a docker image Release-As: 0.0.1 --- .dockerignore | 2 + .github/workflows/release-please.yml | 60 ++++++++++++++++++++++++++++ Dockerfile | 26 ++++++++++++ 3 files changed, 88 insertions(+) create mode 100644 .dockerignore create mode 100644 .github/workflows/release-please.yml create mode 100644 Dockerfile diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..9e9353b --- /dev/null +++ b/.dockerignore @@ -0,0 +1,2 @@ +node_modules/ +vendor/ \ No newline at end of file diff --git a/.github/workflows/release-please.yml b/.github/workflows/release-please.yml new file mode 100644 index 0000000..5d09cd2 --- /dev/null +++ b/.github/workflows/release-please.yml @@ -0,0 +1,60 @@ +on: + push: + branches: + - main + +permissions: + contents: write + packages: write + pull-requests: write + id-token: write + +name: release-please + +jobs: + release-please: + runs-on: ubuntu-latest + outputs: + release_created: ${{ steps.release.outputs.release_created }} + tag_name: ${{ steps.release.outputs.tag_name }} + steps: + - uses: googleapis/release-please-action@v4 + id: release + with: + token: ${{ secrets.GITHUB_TOKEN }} + release-type: php + - run: echo "release_created=${{ steps.release.outputs.release_created }}" >> "$GITHUB_OUTPUT" + - run: echo "tag_name=${{ steps.release.outputs.tag_name }}" >> "$GITHUB_OUTPUT" + + build-and-publish: + runs-on: ubuntu-latest + needs: release-please + if: ${{ needs.release-please.outputs.release_created }} + steps: + - name: Login to Docker 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: + push: true + tags: ghcr.io/ptah-sh/ptah-server:latest,ghcr.io/ptah-sh/ptah-server:${{ needs.release-please.outputs.tag_name }} + # TODO: should we create a github deployment? + deploy: + runs-on: ubuntu-latest + needs: + - release-please + - build-and-publish + if: ${{ needs.release-please.outputs.release_created }} + steps: + - name: Deploy + run: | + curl --fail-with-body -X POST \ + -H 'Content-Type: application/json' \ + -H 'Accept: application/json' \ + -H 'X-Ptah-Token: ${{ secrets.PTAH_TOKEN }}' \ + -d '{"processes":[{"name":"svc","dockerImage":"ghcr.io/ptah-sh/ptah-server:${{ needs.release-please.outputs.tag_name }}"}]}' \ + https://app.ptah.sh/api/v0/services/2/deploy diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..6aadefa --- /dev/null +++ b/Dockerfile @@ -0,0 +1,26 @@ +FROM bitnami/php-fpm:latest + +RUN install_packages nodejs npm \ + && apt-get clean && rm -rf /var/lib/apt/lists /var/cache/apt/archives + +WORKDIR /app + +ENV COMPOSER_ALLOW_SUPERUSER=1 + +COPY package.json . +COPY package-lock.json . + +RUN npm i --frozen-lockfile + +COPY composer.json . +COPY composer.lock . + +RUN composer install --no-scripts + +COPY . . + +RUN composer install + +RUN npm run build \ + && apt-get -y remove npm \ + && apt-get -y autoremove \