Skip to content

Commit

Permalink
kinda deploy to target host
Browse files Browse the repository at this point in the history
  • Loading branch information
Roman Bekkiev committed Dec 6, 2021
1 parent 524abfb commit bbff905
Show file tree
Hide file tree
Showing 11 changed files with 154 additions and 66 deletions.
10 changes: 9 additions & 1 deletion .prettierrc
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
{
"semi": false,
"tabWidth": 4,
"singleQuote": true
"singleQuote": true,
"overrides": [
{
"files": ["*.yaml", "*.yml", "*.json"],
"options": {
"tabWidth": 2
}
}
]
}
2 changes: 1 addition & 1 deletion .typesafe-i18n.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"$schema": "https://unpkg.com/typesafe-i18n@2.52.2/schema/typesafe-i18n.json",
"$schema": "https://unpkg.com/typesafe-i18n@2.55.1/schema/typesafe-i18n.json",
"adapter": "node",
"loadLocalesAsync": false,
"baseLocale": "en",
Expand Down
13 changes: 6 additions & 7 deletions Dockerfile.bot
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
FROM node:lts-alpine
FROM node:14.18.2-alpine3.14
ENV NODE_ENV=production
WORKDIR /usr/src/app
COPY ["package.json", "yarn.lock"]
RUN npm install --production --silent && mv node_modules ../
COPY src tsconfig.json /usr/src/app/
EXPOSE 3000
RUN chown -R node /usr/src/app
COPY ["package.json", "yarn.lock", "/usr/src/app/"]
RUN yarn install --production --silent
COPY . .
# RUN chown -R node /usr/src/app
USER node
CMD yarn start
CMD yarn start:bot
46 changes: 46 additions & 0 deletions deploy/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
---
- hosts: bot
vars:
registry: '{{ lookup("env", "REGISTRY") }}'

tasks:
- name: Establish network
docker_network:
name: tribalizm

- name: Deploy MongoDB
docker_container:
name: mongodb
image: mongo:5.0.4-focal
volumes:
- mongo-data:/data/db
networks:
- name: tribalizm
restart_policy: always
env:
MONGO_INITDB_ROOT_USERNAME: '{{ db_user | string}}'
MONGO_INITDB_ROOT_PASSWORD: '{{ db_pass | string}}'
# to get rid of warnings:
container_default_behavior: no_defaults
network_mode: tribalizm

- name: Log in to AWS ECR
shell: aws ecr get-login-password --region eu-central-1 | docker login --username AWS --password-stdin '{{ registry | string }}'

- name: Deploy Tribalizm bot
docker_container:
name: tribalizm-bot
image: '{{ registry | string }}/tribalizm-bot:1.0'
networks:
- name: tribalizm
ports:
- 5000:3000
restart_policy: always
env:
DB_HOST: mongodb # name of container from 'Deploy MongoDB' task
DB_USER: '{{ db_user | string}}'
DB_PASS: '{{ db_pass | string}}'
BOT_TOKEN: '{{ bot_token | string}}'
# to get rid of warnings:
container_default_behavior: no_defaults
network_mode: tribalizm
4 changes: 4 additions & 0 deletions deploy/host_vars/rblab.net.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,7 @@
ansible_ssh_user: ansible
ansible_ssh_private_key_file: ~/.ssh/ansible_ed25519
ansible_become_pass: 7051d470-97c7-4e4b-bcb0-8284ef6fca45
docker_registry: 296292975264.dkr.ecr.eu-central-1.amazonaws.com
bot_token: 1682280139:AAG8wXiKPxmhG7YI6fX91nV7ctbsPEC3KUg
db_user: muai
db_pass: 5df3a2be-5a13-467a-af82-fe4e579e74d5
10 changes: 9 additions & 1 deletion deploy/install-docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,12 @@
pip:
name:
- docker
- docker-compose
- docker-compose

- name: install AWS ECR credentials helper
become: yes
apt:
name:
- amazon-ecr-credential-helper
- awscli
update_cache: yes
7 changes: 7 additions & 0 deletions deploy/inventory.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,10 @@ rblab.net

[infra]
rblab.net

[localhost]
127.0.0.1


[localhost:vars]
ansible_connection=local
18 changes: 18 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,24 @@ services:
- mongo-data:/data/db
networks:
- tribalizm
tribalizm-bot:
image: tribalizm-bot:1.0
build:
context: .
dockerfile: ./Dockerfile.bot
restart: always
environment:
DB_HOST: "${DB_HOST}"
DB_USER: "${DB_USER}"
DB_PASS: "${DB_PASS}"
BOT_TOKEN: "${BOT_TOKEN}"
networks:
- tribalizm
admin:
image: tribalizm-admin:1.0
build:
context: .
dockerfile: ./Dockerfile.admin
networks:
tribalizm:
name: tribalizm
Expand Down
92 changes: 49 additions & 43 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,45 +1,51 @@
{
"name": "tribalizm",
"version": "1.0.0",
"description": "Real life MMORPG networking",
"main": "index.ts",
"repository": "-",
"author": "RB-Lab",
"license": "UNLICENZED",
"private": true,
"scripts": {
"start:bot": "ts-node --transpile-only src/main.ts",
"start:bot-dev": "nodemon src/plugins/ui/telegram/ui-tests-mock-bot.ts",
"start:admin": "ts-node --transpile-only src/admin.ts",
"test": "ts-node ./node_modules/.bin/jasmine './src/**/*.spec.ts'",
"test:full": "FULL_TEST='true' ts-node ./node_modules/.bin/jasmine './src/**/*.spec.ts'",
"tdd": "tsnd --rs --respawn ./node_modules/.bin/jasmine './src/**/*.spec.ts'",
"depcruise": "depcruise --include-only '^src' --output-type dot src | dot -T svg | depcruise-wrap-stream-in-html > docs/dependecies.html",
"bridge": "ssh -R 5000:localhost:3000 rblab.net",
"i18n": "typesafe-i18n"
},
"dependencies": {
"@types/express": "^4.17.11",
"@types/inquirer": "^8.1.3",
"@types/inquirer-autocomplete-prompt": "^1.3.3",
"@types/mongodb": "^3.6.12",
"@types/node": "^14.14.20",
"express": "^4.17.1",
"inquirer": "^8.2.0",
"inquirer-autocomplete-prompt": "^1.4.0",
"mongodb": "^3.6.6",
"telegraf": "^4.4.2",
"telegraf-calendar-telegram": "^1.5.8",
"ts-node": "^9.1.1",
"typescript": "^4.1.3"
},
"devDependencies": {
"@types/jasmine": "^3.6.2",
"dependency-cruiser": "^10.5.0",
"jasmine": "^3.6.3",
"mongodb-memory-server": "^6.9.6",
"nodemon": "^2.0.7",
"ts-node-dev": "^1.1.6",
"typesafe-i18n": "^2.52.2"
}
"name": "tribalizm",
"version": "1.0.0",
"description": "Real life MMORPG networking",
"main": "index.ts",
"repository": "-",
"author": "RB-Lab",
"license": "UNLICENZED",
"private": true,
"scripts": {
"start:bot": "ts-node --transpile-only src/main.ts",
"start:bot-dev": "nodemon src/plugins/ui/telegram/ui-tests-mock-bot.ts",
"start:admin": "ts-node --transpile-only src/admin.ts",
"build:images": "docker-compose --env-file ./.env.build build",
"push:login": "aws ecr get-login-password --region eu-central-1 | docker login --username AWS --password-stdin \"${REGISTRY}\"",
"push:tag": "sh -c 'docker tag \"${0}\" ${REGISTRY}/\"${0}\"'",
"push:push": "sh -c 'docker push \"${REGISTRY}\"/\"${0}\"'",
"push": "egrep -v '^#' .env.build | xargs && sh -c 'yarn push:login && yarn push:tag \"${0}\" && yarn push:push \"${0}\"'",
"deploy": "export $(egrep -v '^#' .env.build | xargs) && pushd deploy && ansible-playbook deploy.yml && popd",
"test": "ts-node ./node_modules/.bin/jasmine './src/**/*.spec.ts'",
"test:full": "FULL_TEST='true' ts-node ./node_modules/.bin/jasmine './src/**/*.spec.ts'",
"tdd": "tsnd --rs --respawn ./node_modules/.bin/jasmine './src/**/*.spec.ts'",
"depcruise": "depcruise --include-only '^src' --output-type dot src | dot -T svg | depcruise-wrap-stream-in-html > docs/dependecies.html",
"bridge": "ssh -R 5000:localhost:3000 rblab.net",
"i18n": "typesafe-i18n"
},
"dependencies": {
"@types/express": "^4.17.11",
"@types/inquirer": "^8.1.3",
"@types/inquirer-autocomplete-prompt": "^1.3.3",
"@types/mongodb": "^3.6.12",
"@types/node": "^14.14.20",
"express": "^4.17.1",
"inquirer": "^8.2.0",
"inquirer-autocomplete-prompt": "^1.4.0",
"mongodb": "^3.6.6",
"telegraf": "^4.4.2",
"telegraf-calendar-telegram": "^1.5.8",
"ts-node": "^9.1.1",
"typesafe-i18n": "^2.55.1",
"typescript": "^4.1.3"
},
"devDependencies": {
"@types/jasmine": "^3.6.2",
"dependency-cruiser": "^10.5.0",
"jasmine": "^3.6.3",
"mongodb-memory-server": "^6.9.6",
"nodemon": "^2.0.7",
"ts-node-dev": "^1.1.6"
}
}
3 changes: 1 addition & 2 deletions src/plugins/ui/i18n/i18n-types.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// This file was auto-generated by 'typesafe-i18n'. Any manual changes will be overwritten.
/* eslint-disable */
import type { BaseTranslation as BaseTranslationType } from 'typesafe-i18n'
import type { LocalizedString } from 'typesafe-i18n'
import type { BaseTranslation as BaseTranslationType, LocalizedString } from 'typesafe-i18n'

export type BaseTranslation = BaseTranslationType
export type BaseLocale = 'en'
Expand Down
15 changes: 4 additions & 11 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2560,17 +2560,10 @@ typegram@^3.4.2:
resolved "https://registry.yarnpkg.com/typegram/-/typegram-3.5.1.tgz#802ff7d2f29c6ea6917ffab4a7d02814af29e47d"
integrity sha512-cDCj4KMycgpdoDihK9LbJbLBBrZdDDQskR4aeoLawyk6YS2GXmr4jncGQGvu6Wav1iNTGvSDwr4b3ipLHh1edA==

typesafe-i18n@^2.52.2:
version "2.52.2"
resolved "https://registry.yarnpkg.com/typesafe-i18n/-/typesafe-i18n-2.52.2.tgz#533b077346647980ed9e4431f0a27dfeae544c51"
integrity sha512-A3gzQCwHgJ7OynJb/wUmx7kmdUw+p5rf+iHgcP9raLAjivH/pUeMKq0n8Kh3eFb9336EUC4nHcP2Z67epkvCWQ==
dependencies:
typesafe-utils "^1.16.2"

typesafe-utils@^1.16.2:
version "1.16.2"
resolved "https://registry.yarnpkg.com/typesafe-utils/-/typesafe-utils-1.16.2.tgz#ba3647f005eabb4f037995e7b4e706ab15af6544"
integrity sha512-5Ej1sd5V541LPxlJEs4JKpsmF0zvMcwakXJ/s2N9SpdYAEr6CQcgr2COF350nxaO1FSbHYfL+tEKBcMcLDrdOQ==
typesafe-i18n@^2.55.1:
version "2.55.1"
resolved "https://registry.yarnpkg.com/typesafe-i18n/-/typesafe-i18n-2.55.1.tgz#5b8a2228017b918cd49dfaea325ffaa63ff41fa2"
integrity sha512-zEU2PhhrcI1M9erZab1ieBMyc/oVDwQguLutK497XMnwZzcMJlo1XrkI4JXshnj8R7TQ+3Y7s2Bgbeg2VI2utg==

typescript@^4.1.3:
version "4.1.3"
Expand Down

0 comments on commit bbff905

Please sign in to comment.