diff --git a/.github/workflows/build-docker-image.yml b/.github/workflows/build-docker-image.yml new file mode 100644 index 0000000..8ad8529 --- /dev/null +++ b/.github/workflows/build-docker-image.yml @@ -0,0 +1,51 @@ +name: Build Docker Image + +on: + workflow_call: + inputs: + imageName: + type: string + required: true + description: 'Name of the image to build' + dockerfilePath: + type: string + required: true + description: 'Path to the Dockerfile' + target: + type: string + required: false + description: 'Target to build' + +jobs: + build-and-push: + runs-on: ubuntu-latest + + steps: + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Docker meta + id: meta + uses: docker/metadata-action@v5 + with: + images: | + ${{ inputs.imageName }} + tags: | + type=ref,event=branch + type=ref,event=pr + type=semver,pattern={{version}} + + - name: Login to Docker Hub + uses: docker/login-action@v1 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + + - name: Build Image + uses: docker/build-push-action@v2 + with: + context: . + file: ${{ inputs.dockerfilePath }} + target: ${{ inputs.target }} + push: true + tags: ${{ steps.meta.outputs.tags }} diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..a95029d --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,32 @@ +name: Build + +on: + workflow_call: + +jobs: + build-backend: + uses: ./.github/workflows/build-docker-image.yml + with: + imageName: 'linuxodyssey/backend' + dockerfilePath: './server/Dockerfile' + target: prod + + build-frontend: + uses: ./.github/workflows/build-docker-image.yml + with: + imageName: 'linuxodyssey/frontend' + dockerfilePath: './app/Dockerfile' + target: prod + + build-analytics: + uses: ./.github/workflows/build-docker-image.yml + with: + imageName: 'linuxodyssey/analytics' + dockerfilePath: './packages/analytics/Dockerfile' + target: prod + + build-base: + uses: ./.github/workflows/build-docker-image.yml + with: + imageName: 'linuxodyssey/base' + dockerfilePath: './quests/Dockerfile' diff --git a/.github/workflows/ci-checks.yml b/.github/workflows/ci-checks.yml new file mode 100644 index 0000000..2d7bb93 --- /dev/null +++ b/.github/workflows/ci-checks.yml @@ -0,0 +1,45 @@ +name: CI Checks + +on: + workflow_call: + +jobs: + ci: + runs-on: ubuntu-latest + + steps: + - name: Checkout + uses: actions/checkout@v3 + + - uses: actions/setup-node@v3 + with: + node-version: 20 + + - name: Install dependencies + run: yarn install + + - name: Lint + run: yarn lint + + - name: Test + run: yarn test + + e2e: + runs-on: ubuntu-latest + steps: + - name: Checkout Code + uses: actions/checkout@v3 + + - name: Build Test Environment, Stage 1 + run: docker-compose -f docker-compose.testing.yml build base backend app-test + + - name: Build Test Quests + run: docker-compose -f docker-compose.testing.yml run --rm backend yarn build:quests + + - name: Run Cypress Tests + env: + GOOGLE_CLIENT_ID: ${{ secrets.GOOGLE_CLIENT_ID }} + GOOGLE_CLIENT_SECRET: ${{ secrets.GOOGLE_CLIENT_SECRET }} + GITHUB_CLIENT_ID: ${{ secrets.GITHUB_CLIENT_ID }} + GITHUB_CLIENT_SECRET: ${{ secrets.GITHUB_CLIENT_SECRET }} + run: docker-compose -f docker-compose.testing.yml run cypress diff --git a/.github/workflows/ci_cd.yml b/.github/workflows/ci_cd.yml deleted file mode 100644 index e90c3bb..0000000 --- a/.github/workflows/ci_cd.yml +++ /dev/null @@ -1,110 +0,0 @@ -name: CI/CD - -on: - push: - -jobs: - ci: - runs-on: ubuntu-latest - - steps: - - name: Checkout - uses: actions/checkout@v3 - - - uses: actions/setup-node@v3 - with: - node-version: 20 - - - name: Install dependencies - run: yarn install - - - name: Lint - run: yarn lint - - - name: Test - run: yarn test - - e2e: - runs-on: ubuntu-latest - steps: - - name: Checkout Code - uses: actions/checkout@v3 - - - name: Build Test Environment, Stage 1 - run: docker-compose -f docker-compose.testing.yml build base backend app-test - - - name: Build Test Quests - run: docker-compose -f docker-compose.testing.yml run --rm backend yarn build:quests - - - name: Run Cypress Tests - env: - GOOGLE_CLIENT_ID: ${{ secrets.GOOGLE_CLIENT_ID }} - GOOGLE_CLIENT_SECRET: ${{ secrets.GOOGLE_CLIENT_SECRET }} - GITHUB_CLIENT_ID: ${{ secrets.GITHUB_CLIENT_ID }} - GITHUB_CLIENT_SECRET: ${{ secrets.GITHUB_CLIENT_SECRET }} - run: docker-compose -f docker-compose.testing.yml run cypress - - build-and-push: - needs: - - ci - - e2e - if: github.ref == 'refs/heads/main' - runs-on: ubuntu-latest - - steps: - - name: Checkout - uses: actions/checkout@v3 - - - name: Login to Docker Hub - uses: docker/login-action@v1 - with: - username: ${{ secrets.DOCKERHUB_USERNAME }} - password: ${{ secrets.DOCKERHUB_TOKEN }} - - - name: Build backend - uses: docker/build-push-action@v2 - with: - context: . - file: ./server/Dockerfile - target: prod - push: true - tags: docker.io/${{ secrets.DOCKERHUB_USERNAME }}/linux-odyssey:backend - - - name: Build app - uses: docker/build-push-action@v2 - with: - context: . - file: ./app/Dockerfile - target: prod - push: true - tags: docker.io/${{ secrets.DOCKERHUB_USERNAME }}/linux-odyssey:app - - - name: Build analytics - uses: docker/build-push-action@v2 - with: - context: . - file: ./packages/analytics/Dockerfile - target: prod - push: true - tags: docker.io/${{ secrets.DOCKERHUB_USERNAME }}/linux-odyssey:analytics - - - name: Build base image - uses: docker/build-push-action@v2 - with: - context: . - file: ./quests/Dockerfile - push: true - tags: docker.io/${{ secrets.DOCKERHUB_USERNAME }}/linux-odyssey:base - - deploy: - needs: build-and-push - runs-on: ubuntu-latest - - steps: - - name: SSH into server and update service - uses: appleboy/ssh-action@master - with: - host: ${{ secrets.SERVER_HOST }} - port: ${{ secrets.SERVER_PORT }} - username: ${{ secrets.SERVER_USER }} - key: ${{ secrets.SERVER_SSH_KEY }} diff --git a/.github/workflows/production.yml b/.github/workflows/production.yml new file mode 100644 index 0000000..e82c2f0 --- /dev/null +++ b/.github/workflows/production.yml @@ -0,0 +1,27 @@ +name: Production Deployment + +on: + push: + tags: + - 'v*' + +jobs: + ci-checks: + uses: ./.github/workflows/ci-checks.yml + + build: + needs: ci-checks + uses: ./.github/workflows/build.yml + + deploy: + needs: build + runs-on: ubuntu-latest + + steps: + - name: SSH into server and update service + uses: appleboy/ssh-action@master + with: + host: ${{ secrets.SERVER_HOST }} + port: ${{ secrets.SERVER_PORT }} + username: ${{ secrets.SERVER_USER }} + key: ${{ secrets.SERVER_SSH_KEY }} diff --git a/.github/workflows/code_review.yml b/.github/workflows/pull-request.yml similarity index 64% rename from .github/workflows/code_review.yml rename to .github/workflows/pull-request.yml index e15258e..56a6180 100644 --- a/.github/workflows/code_review.yml +++ b/.github/workflows/pull-request.yml @@ -1,11 +1,13 @@ -name: Code Review GPT +name: Pull Request Workflow on: pull_request: - branches: [main] jobs: - run_code_review: + ci-checks: + uses: ./.github/workflows/ci-checks.yml + + code_review: permissions: pull-requests: write runs-on: ubuntu-latest @@ -18,5 +20,9 @@ jobs: uses: mattzcarey/code-review-gpt@v0.1.4-alpha with: OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }} - MODEL: 'gpt-3.5-turbo' + MODEL: 'gpt-4-1106-preview' GITHUB_TOKEN: ${{ github.token }} + + build: + uses: ./.github/workflows/build.yml + needs: ci-checks diff --git a/.github/workflows/staging.yml b/.github/workflows/staging.yml new file mode 100644 index 0000000..085090a --- /dev/null +++ b/.github/workflows/staging.yml @@ -0,0 +1,27 @@ +name: Staging Deployment + +on: + push: + branches: + - main + +jobs: + ci-checks: + uses: ./.github/workflows/ci-checks.yml + + build: + uses: ./.github/workflows/build.yml + needs: ci-checks + + deploy: + needs: build + runs-on: ubuntu-latest + + steps: + - name: SSH into server and update service + uses: appleboy/ssh-action@master + with: + host: ${{ secrets.SERVER_HOST }} + port: ${{ secrets.SERVER_PORT }} + username: ${{ secrets.SERVER_USER }} + key: ${{ secrets.SERVER_SSH_KEY }} diff --git a/docker-compose.prod.yml b/docker-compose.prod.yml index 23c00ac..d5b0eed 100644 --- a/docker-compose.prod.yml +++ b/docker-compose.prod.yml @@ -1,7 +1,7 @@ version: '3' services: app: - image: lancatlin/linux-odyssey:app + image: linuxodyssey/frontend depends_on: - backend restart: always @@ -13,8 +13,9 @@ services: internal: ports: - 8080:80 + backend: - image: lancatlin/linux-odyssey:backend + image: linuxodyssey/backend depends_on: - db restart: always @@ -36,7 +37,7 @@ services: - TRUSTED_PROXIES=${TRUSTED_PROXIES} analytics: - image: lancatlin/linux-odyssey:analytics + image: linuxodyssey/analytics build: context: . dockerfile: packages/analytics/Dockerfile @@ -76,7 +77,7 @@ services: - BUG_REPORT_URL=${BUG_REPORT_URL} base: - image: lancatlin/linux-odyssey:base + image: linuxodyssey/base build: context: . dockerfile: ./quests/Dockerfile