Skip to content

Commit

Permalink
make it work (#114)
Browse files Browse the repository at this point in the history
  • Loading branch information
dhenkel92 authored May 4, 2024
1 parent 2772461 commit c7eb161
Show file tree
Hide file tree
Showing 32 changed files with 509 additions and 156 deletions.
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*/**/.terraform*
14 changes: 7 additions & 7 deletions async-server-provisioner/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM node:14.17.0-stretch as build
FROM node:21.7-bullseye-slim as build

ENV NODE_ENV=development
WORKDIR /usr/src/app
Expand All @@ -11,17 +11,17 @@ RUN npm ci
COPY async-server-provisioner/ .
RUN npm run build

FROM node:14.17.0-stretch
FROM node:21.7-bullseye-slim

ENV NODE_ENV=production
WORKDIR /usr/src/app

RUN apt-get update \
&& apt-get install -y wget unzip \
&& wget https://releases.hashicorp.com/terraform/1.1.9/terraform_1.1.9_linux_amd64.zip -O /root/terraform.zip \
&& unzip -d /root/ /root/terraform.zip \
&& mv /root/terraform /usr/bin/terraform \
&& wget https://github.com/gruntwork-io/terragrunt/releases/download/v0.36.7/terragrunt_linux_amd64 -O /usr/bin/terragrunt \
&& apt-get install -y wget curl unzip \
&& curl --proto '=https' --tlsv1.2 -fsSL https://get.opentofu.org/install-opentofu.sh -o install-opentofu.sh \
&& chmod +x install-opentofu.sh \
&& ./install-opentofu.sh --install-method deb \
&& wget https://github.com/gruntwork-io/terragrunt/releases/download/v0.58.0/terragrunt_linux_amd64 -O /usr/bin/terragrunt \
&& chmod +x /usr/bin/terragrunt

COPY --from=build /usr/src/app/package.json .
Expand Down
2 changes: 1 addition & 1 deletion async-server-provisioner/config/default.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@ datadog:
api_key: placeholder

cloudGame:
ansibleBranch: create-restore-backups
ansibleBranch: main
apiUrl: http://host.docker.internal:1337
apiToken: placeholder
2 changes: 1 addition & 1 deletion async-server-provisioner/src/ServiceLocator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ export default class ServiceLocator {
}
const adapter = await this.getMySqlAdapter();
const dirtyAdapter = await this.getDirtyMySqlAdapter();
const repo = new GameDeploymentRepository(adapter, dirtyAdapter);
const repo = new GameDeploymentRepository(adapter, dirtyAdapter, this.getLogger());

this.setCache('GameDeploymentRepository', repo);
return repo;
Expand Down
7 changes: 4 additions & 3 deletions async-server-provisioner/src/adapters/GraphQlAdapter.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import * as config from 'config';
import pino from 'pino';

const apiUrl = config.get<string>('cloudGame.apiUrl');

export async function gqlQuery(query: string, data: any): Promise<any> {
const res = await fetch(`${apiUrl}/graphql`, {
export async function gqlQuery(logger: pino.Logger, query: string, data: any): Promise<Response> {
logger.child({ url: `${apiUrl}/graphql`, query, data }).info('Fetch API data');
return fetch(`${apiUrl}/graphql`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
Expand All @@ -15,5 +17,4 @@ export async function gqlQuery(query: string, data: any): Promise<any> {
variables: data,
}),
});
return res.json();
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { GameDeployment, gameDeploymentFactory } from '../entities/GameDeploymen
import { v4 } from 'uuid';
import { TerraformGSOutput } from '../services/TerraformService';
import { gqlQuery } from '../adapters/GraphQlAdapter';
import pino from 'pino';

const query = `
query($id: ID) {
Expand Down Expand Up @@ -54,7 +55,8 @@ query($id: ID) {
export default class GameDeploymentRepository {
constructor(
private mysqlAdapter: MySqlAdapter,
private dirtyMysqlAdapter: MySqlAdapter
private dirtyMysqlAdapter: MySqlAdapter,
private logger: pino.Logger
) {}

public async getDeployment(): Promise<GameDeployment | null> {
Expand Down Expand Up @@ -83,7 +85,12 @@ export default class GameDeploymentRepository {
return null;
}

const data = await gqlQuery(query, { id: rows[0].gd_id });
const res = await gqlQuery(this.logger, query, { id: rows[0].gd_id });
const data = await res.json();
if (data.errors && data.errors.length != 0) {
this.logger.child({ errors: data.errors }).error('Failed to fetch game deployment data');
return null;
}
const gameDeployment = gameDeploymentFactory(uuid, data);
// eslint-disable-next-line no-console
console.log(JSON.stringify(gameDeployment, null, 2));
Expand Down
2 changes: 2 additions & 0 deletions backend/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules
build
8 changes: 4 additions & 4 deletions backend/.strapi-updater.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"latest": "4.24.0",
"lastUpdateCheck": 1714554785847,
"lastNotification": 1655564816994
}
"latest": "4.24.1",
"lastUpdateCheck": 1714740073758,
"lastNotification": 1714740179673
}
4 changes: 2 additions & 2 deletions backend/Dockerfile-prod-be
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM node:16.14-bullseye as build
FROM node:21.7-bullseye-slim as build

ENV NODE_ENV=production
WORKDIR /usr/src/app
Expand All @@ -10,7 +10,7 @@ RUN npm ci

COPY backend .

FROM node:16.14-bullseye
FROM node:21.7-bullseye-slim

WORKDIR /usr/src/app

Expand Down
8 changes: 6 additions & 2 deletions backend/Dockerfile-prod-fe
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
FROM node:16.14-bullseye as build
FROM node:21.7-bullseye-slim as build

ARG ADMIN_URL=http://localhost:1337/admin
ARG ADMIN_URL=/
ENV ADMIN_URL=$ADMIN_URL

ARG SERVE_ADMIN_PANEL=false
ENV SERVE_ADMIN_PANEL=$SERVE_ADMIN_PANEL

ARG SERVER_URL=http://localhost:1337
ENV SERVER_URL=$SERVER_URL

Expand All @@ -11,6 +14,7 @@ WORKDIR /usr/src/app

COPY package.json .
COPY package-lock.json .
COPY prod-patches patches

RUN npm ci

Expand Down
3 changes: 2 additions & 1 deletion backend/config/admin.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
module.exports = ({ env }) => ({
url: env("ADMIN_URL", "http://localhost:1337/admin"),
url: env("ADMIN_URL", "/admin/"),
serveAdminPanel: env("SERVE_ADMIN_PANEL", true),
auth: {
secret: env("ADMIN_JWT_SECRET"),
},
Expand Down
Loading

0 comments on commit c7eb161

Please sign in to comment.