From 0251b4910547aec94fdfe0da4585bc309c75f999 Mon Sep 17 00:00:00 2001 From: thomasgouveia Date: Tue, 13 Dec 2022 17:52:05 +0100 Subject: [PATCH] ci: update build workflow --- .dockerignore | 10 ++++++- .github/workflows/ci.yml | 17 ----------- .github/workflows/pull_request.yml | 33 ++++++++++++++++++++ .github/workflows/release.yml | 48 ++++++++++++++++++++++++++++++ Dockerfile | 5 ---- Dockerfile.app | 14 +++++++++ 6 files changed, 104 insertions(+), 23 deletions(-) delete mode 100644 .github/workflows/ci.yml create mode 100644 .github/workflows/pull_request.yml create mode 100644 .github/workflows/release.yml delete mode 100644 Dockerfile create mode 100644 Dockerfile.app diff --git a/.dockerignore b/.dockerignore index b462bc98..c5a1b0f8 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,3 +1,11 @@ node_modules -build +dist +.turbo +.vite README.md +.github +.idea +.editorconfig +.gitignore +CONTRIBUTING.md +sonar-project.properties diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml deleted file mode 100644 index 13ed771c..00000000 --- a/.github/workflows/ci.yml +++ /dev/null @@ -1,17 +0,0 @@ -name: CI - -on: - push: - branches: - - main - tags: - - "v*" - pull_request: - branches: - - main - workflow_dispatch: - -jobs: - frontend: - uses: polyflix/.github/.github/workflows/frontend-v2.yml@main - secrets: inherit diff --git a/.github/workflows/pull_request.yml b/.github/workflows/pull_request.yml new file mode 100644 index 00000000..61bb35a0 --- /dev/null +++ b/.github/workflows/pull_request.yml @@ -0,0 +1,33 @@ +name: Pull Requests + +on: + pull_request: + branches: + - main + +jobs: + automated_review: + runs-on: ubuntu-22.04 + steps: + - uses: actions/checkout@v3 + + - uses: pnpm/action-setup@v2 + with: + version: 7 + + - uses: actions/setup-node@v3 + with: + node-version: 16.x + cache: 'pnpm' + + - name: Install dependencies + run: pnpm install + + - name: Audit dependencies + run: pnpm audit + + - name: Linting code + run: pnpm run --if-present lint + + - name: Check code formatting + run: pnpm run --if-present format diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 00000000..64520c93 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,48 @@ +name: Release + +on: + push: + branches: [ main ] + +jobs: + drafter: + permissions: + contents: write + runs-on: ubuntu-22.04 + steps: + - uses: release-drafter/release-drafter@v5 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + package: + needs: drafter + runs-on: ubuntu-22.04 + steps: + - uses: actions/checkout@v3 + - uses: docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + - id: meta + uses: docker/metadata-action@v4 + with: + images: ghcr.io/${{ github.repository }} + flavor: ${{ inputs.docker-metadata-flavor }} + - id: extract-env + run: | + if [[ "$GITHUB_REF_TYPE" == tag ]] + then + echo "environment=production" >> $GITHUB_OUTPUT + else + echo "environment=qa" >> $GITHUB_OUTPUT + fi + - uses: docker/build-push-action@v3 + with: + build-args: | + BUILD_MODE=${{ steps.extract-env.outputs.environment }} + context: . + file: Dockerfile.app + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} diff --git a/Dockerfile b/Dockerfile deleted file mode 100644 index 827fcf2e..00000000 --- a/Dockerfile +++ /dev/null @@ -1,5 +0,0 @@ -FROM nginx:stable-alpine -COPY apps/polyflix/dist /usr/share/nginx/html -COPY .docker/nginx.conf /etc/nginx/conf.d/default.conf -EXPOSE 8080 -CMD [ "nginx", "-g", "daemon off;" ] diff --git a/Dockerfile.app b/Dockerfile.app new file mode 100644 index 00000000..58bedbf8 --- /dev/null +++ b/Dockerfile.app @@ -0,0 +1,14 @@ +ARG BUILD_MODE=production + +FROM node:16 as build-web +WORKDIR /build +COPY . . +RUN npm install -g pnpm && \ + pnpm install --frozen-lockfile && \ + BUILD_MODE=${BUILD_MODE} pnpm build + +FROM nginx:stable-alpine +COPY --from=build-web /build/apps/polyflix/dist /usr/share/nginx/html +COPY .docker/nginx.conf /etc/nginx/conf.d/default.conf +EXPOSE 8080 +CMD [ "nginx", "-g", "daemon off;" ]