diff --git a/.docker/scripts/start.sh b/.docker/scripts/start.sh new file mode 100644 index 0000000..f7aaa8f --- /dev/null +++ b/.docker/scripts/start.sh @@ -0,0 +1,7 @@ +#!/bin/bash + +echo "Applying Database Migrations" +/app/node_modules/.bin/prisma migrate deploy + +echo "Starting Application" +node /app/lib/servers/graphql-main.js \ No newline at end of file diff --git a/.env.example b/.env.example index 0378802..ba996ae 100644 --- a/.env.example +++ b/.env.example @@ -1,8 +1,8 @@ # If ran on docker linux -DATABASE_URL="postgresql://username:password@:5432/autifynetwork" +DATABASE_URL="postgresql://username:password@:5432/ranter" # If ran on docker mac -DATABASE_URL="postgresql://username:password@host.docker.internal:5432/autifynetwork" +DATABASE_URL="postgresql://username:password@host.docker.internal:5432/ranter" # If ran locally -DATABASE_URL="postgresql://username:password@localhsot:5432/autifynetwork" +DATABASE_URL="postgresql://username:password@localhsot:5432/ranter" diff --git a/.github/workflows/build-image.yml b/.github/workflows/build-image.yml new file mode 100644 index 0000000..cfa1cdf --- /dev/null +++ b/.github/workflows/build-image.yml @@ -0,0 +1,33 @@ +name: Build and Push Docker image + +on: + push: + branches: + - 'deployment-ci' + +jobs: + build-and-push: + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v2 + + - name: Set up QEMU + uses: docker/setup-qemu-action@v1 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v1 + + - name: Login to DockerHub + uses: docker/login-action@v1 + with: + username: ${{ secrets.DOCKER_HUB_USERNAME }} + password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }} + + - name: Build and push Docker image + uses: docker/build-push-action@v2 + with: + context: . + push: true + tags: ${{ secrets.DOCKER_HUB_USERNAME }}/my-app:latest diff --git a/.github/workflows/spinup.yml b/.github/workflows/spinup.yml new file mode 100644 index 0000000..7468341 --- /dev/null +++ b/.github/workflows/spinup.yml @@ -0,0 +1,33 @@ +name: Spinup Server + +on: + push: + branches: ['deployment-ci'] + +jobs: + spinup-server: + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v2 + + - name: Set up Node.js + uses: actions/setup-node@v2 + with: + node-version: '18' + + - name: Install direnv + run: sudo apt-get install direnv -y + + - name: Install dependencies + run: yarn install + + - name: Build the app + run: yarn build + + - name: Run Server & Get Healthz + run: | + . ./.envrc && yarn start & + sleep 5 + curl --fail http://localhost:4000/healthz diff --git a/Dockerfile b/Dockerfile index 42e6e3e..bbcaca2 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,10 +1,23 @@ -FROM node:18 +FROM node:18 AS BUILD_IMAGE WORKDIR /app # Install dependencies -COPY *.json ./yarn.lock ./ +COPY . . RUN yarn install --frozen-lockfile -# Run Source Code -COPY . . \ No newline at end of file +# Build Source Code +COPY ./src ./src +RUN yarn build +RUN yarn install --frozen-lockfile --production + +FROM node:18 +COPY --from=BUILD_IMAGE /app/lib /app/lib +COPY --from=BUILD_IMAGE /app/node_modules /app/node_modules +COPY --from=BUILD_IMAGE /app/prisma /app/prisma +COPY --from=BUILD_IMAGE /app/.docker/scripts /app/.docker/scripts + +WORKDIR /app +COPY ./*.js ./package.json ./tsconfig.json ./yarn.lock ./default.yaml ./ + +CMD [".docker/scripts/start.sh"] \ No newline at end of file diff --git a/ci/deployment.yml b/ci/deployment.yml new file mode 100644 index 0000000..bf9c065 --- /dev/null +++ b/ci/deployment.yml @@ -0,0 +1,19 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: ranter-deploy-dev +spec: + replicas: 3 + selector: + matchLabels: + app: ranter + template: + metadata: + labels: + app: ranter + spec: + containers: + - name: ranter + image: spantheslayer/ranter-dev-image:latest + ports: + - containerPort: 8080 diff --git a/eslintonld.json b/eslintonld.json deleted file mode 100644 index 880110b..0000000 --- a/eslintonld.json +++ /dev/null @@ -1,69 +0,0 @@ -{ - "env": { - "node": true - }, - "parser": "@typescript-eslint/parser", - "parserOptions": { - "project": "tsconfig.json", - "sourceType": "module" - }, - "plugins": ["eslint-plugin-import", "@typescript-eslint", "prettier"], - "extends": [ - "eslint:recommended", - "plugin:import/recommended", - "plugin:import/typescript", - "plugin:@typescript-eslint/recommended", - "prettier" - ], - "rules": { - "@typescript-eslint/no-extra-semi": "off", - - "@typescript-eslint/prefer-for-of": "error", - "@typescript-eslint/unified-signatures": "error", - - "import/no-deprecated": "error", - "import/no-extraneous-dependencies": "error", - "import/no-unassigned-import": "error", - "import/no-unresolved": "off", - "import/order": [ - "error", - { "newlines-between": "always-and-inside-groups" } - ], - - "prettier/prettier": [ - "error", - { - "semi": false, - "trailingComma": "none", - "quoteProps": "consistent", - "singleQuote": true, - "tabWidth": 4, - "useTabs": false, - "bracketSpacing": true, - "arrowParens": "always", - "proseWrap": "preserve", - "endOfLine": "lf" - } - ], - - "arrow-body-style": "off", - "prefer-arrow-callback": "off", - - "no-empty": ["error", { "allowEmptyCatch": true }], - "no-new-wrappers": "error", - "no-param-reassign": "error", - "no-return-await": "error", - "no-sequences": "error", - "no-throw-literal": "error", - "no-void": "error", - "@typescript-eslint/explicit-module-boundary-types": "off", - "no-async-promise-executor": "off" - }, - "settings": { - "import/resolver": { - "node": { - "paths": ["."] - } - } - } -}