From 5e8e2e4e3070312b6e9dfc45fc2f424a0dd56abf Mon Sep 17 00:00:00 2001 From: Sv443 Date: Fri, 12 Jan 2024 22:37:59 +0100 Subject: [PATCH] feat: deployment stuff --- .github/workflows/build-deploy-prod.yml | 50 ++++++++++++++++++++++++ .github/workflows/build-deploy-stage.yml | 50 ++++++++++++++++++++++++ .github/workflows/codeql-analysis.yml | 45 --------------------- .github/workflows/lint-and-analyze.yml | 45 +++++++++++++++++++++ Dockerfile | 4 +- 5 files changed, 147 insertions(+), 47 deletions(-) create mode 100644 .github/workflows/build-deploy-prod.yml create mode 100644 .github/workflows/build-deploy-stage.yml delete mode 100644 .github/workflows/codeql-analysis.yml create mode 100644 .github/workflows/lint-and-analyze.yml diff --git a/.github/workflows/build-deploy-prod.yml b/.github/workflows/build-deploy-prod.yml new file mode 100644 index 00000000..def23d44 --- /dev/null +++ b/.github/workflows/build-deploy-prod.yml @@ -0,0 +1,50 @@ +name: "Build and Deploy to Prod" + +on: + push: + branches: + - main + +concurrency: ${{ github.workflow }}-${{ github.ref }} + +jobs: + publish: + runs-on: ubuntu-latest + strategy: + matrix: + node-version: [20.x] + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-node@v3 + with: + node-version: ${{ matrix.node-version }} + + - name: Determine latest version + run: echo "APP_VERSION=$(git describe --tags || git rev-parse --short HEAD)" >> $GITHUB_ENV + + - name: Login to GitHub Container Registry + uses: docker/login-action@v2 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Build docker image and push + uses: docker/build-push-action@v4 + with: + context: ./ + file: ./Dockerfile + build-args: APP_VERSION=${{ env.APP_VERSION }} + push: true + tags: ghcr.io/sv443-network/jokeapi:latest + + - name: Delete old packages + uses: actions/delete-package-versions@v4 + with: + package-name: ${{ github.event.repository.name }} + package-type: "container" + min-versions-to-keep: 3 + delete-only-untagged-versions: "true" + + - name: Deploy to prod + run: echo "TODO Trigger prod deployment here" diff --git a/.github/workflows/build-deploy-stage.yml b/.github/workflows/build-deploy-stage.yml new file mode 100644 index 00000000..f7b4e50f --- /dev/null +++ b/.github/workflows/build-deploy-stage.yml @@ -0,0 +1,50 @@ +name: "Build and Deploy to Stage" + +on: + push: + branches: + - v3 + +concurrency: ${{ github.workflow }}-${{ github.ref }} + +jobs: + publish: + runs-on: ubuntu-latest + strategy: + matrix: + node-version: [20.x] + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-node@v3 + with: + node-version: ${{ matrix.node-version }} + + - name: Determine latest version + run: echo "APP_VERSION=$(git describe --tags || git rev-parse --short HEAD)" >> $GITHUB_ENV + + - name: Login to GitHub Container Registry + uses: docker/login-action@v2 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Build docker image and push + uses: docker/build-push-action@v4 + with: + context: ./ + file: ./Dockerfile + build-args: APP_VERSION=${{ env.APP_VERSION }} + push: true + tags: ghcr.io/sv443-network/jokeapi-stage:latest + + - name: Delete old packages + uses: actions/delete-package-versions@v4 + with: + package-name: ${{ github.event.repository.name }} + package-type: "container" + min-versions-to-keep: 3 + delete-only-untagged-versions: "true" + + - name: Deploy to stage + run: echo "TODO Trigger stage deployment here" diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml deleted file mode 100644 index 8df8a497..00000000 --- a/.github/workflows/codeql-analysis.yml +++ /dev/null @@ -1,45 +0,0 @@ -name: "CodeQL" - -on: - push: - branches: [ master ] - pull_request: - # The branches below must be a subset of the branches above - branches: [ master ] - # schedule: - # - cron: '23 12 * * 4' - -jobs: - analyze: - name: Analyze Code - runs-on: ubuntu-latest - permissions: - actions: read - contents: read - security-events: write - - strategy: - matrix: - language: [ 'javascript' ] - # CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python' ] - # Learn more: - # https://docs.github.com/en/free-pro-team@latest/github/finding-security-vulnerabilities-and-errors-in-your-code/configuring-code-scanning#changing-the-languages-that-are-analyzed - - steps: - - name: Checkout repository and submodules - uses: actions/checkout@v3 - with: - submodules: recursive - - # Initializes the CodeQL tools for scanning. - - name: Initialize CodeQL - uses: github/codeql-action/init@v2 - with: - languages: ${{ matrix.language }} - # If you wish to specify custom queries, you can do so here or in a config file. - # By default, queries listed here will override any specified in a config file. - # Prefix the list here with "+" to use these queries and those in the config file. - # queries: ./path/to/local/query, your-org/your-repo/queries@main - - - name: Perform CodeQL Analysis - uses: github/codeql-action/analyze@v2 diff --git a/.github/workflows/lint-and-analyze.yml b/.github/workflows/lint-and-analyze.yml new file mode 100644 index 00000000..c54f814b --- /dev/null +++ b/.github/workflows/lint-and-analyze.yml @@ -0,0 +1,45 @@ +name: "Lint and Analyze Code" + +on: + push: + branches: [main, v3] + pull_request: + branches: [main, v3] + +jobs: + lint: + name: Lint Code + runs-on: ubuntu-latest + strategy: + matrix: + node-version: [20.x] + + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-node@v3 + with: + node-version: ${{ matrix.node-version }} + - name: Install dependencies + run: npm ci + - name: Lint + run: npm run lint + + analyze: + name: Analyze Code + runs-on: ubuntu-latest + permissions: + actions: read + contents: read + security-events: write + strategy: + matrix: + language: ["javascript"] + + steps: + - uses: actions/checkout@v3 + - name: Initialize CodeQL + uses: github/codeql-action/init@v2 + with: + languages: ${{ matrix.language }} + - name: Perform CodeQL Analysis + uses: github/codeql-action/analyze@v2 diff --git a/Dockerfile b/Dockerfile index 10e75c94..34cb9565 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,11 +1,11 @@ -FROM node:alpine +FROM node:20-alpine # Set working directory WORKDIR /app # Install app dependencies COPY package.json ./ -RUN npm install +RUN npm i # Copy app source code COPY . .