From 46b95cfca8e872296933ed8ba3632d3b9de80d95 Mon Sep 17 00:00:00 2001 From: Smith Date: Fri, 24 Feb 2023 19:00:35 +0100 Subject: [PATCH] fli.io files & create, configure, deploy actions --- .dockerignore | 16 ++++++++++++ .github/workflows/configure.yml | 38 +++++++++++++++++++++++++++ .github/workflows/create.yml | 18 +++++++++++++ .github/workflows/deploy.yml | 23 ++++++++++------- .gitignore | 1 + .nvmrc | 2 +- Dockerfile | 34 ++++++++++++++++++++++++ fly.toml | 46 +++++++++++++++++++++++++++++++++ 8 files changed, 167 insertions(+), 11 deletions(-) create mode 100644 .dockerignore create mode 100644 .github/workflows/configure.yml create mode 100644 .github/workflows/create.yml create mode 100644 Dockerfile create mode 100644 fly.toml diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..2710795 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,16 @@ +fly.toml +Dockerfile +.dockerignore +node_modules +.git +*.tsbuildinfo +app.json +azuredeploy.json +Procfile +.nvmrc +.env.example +.env +.do +.github +.vscode +data/*.json diff --git a/.github/workflows/configure.yml b/.github/workflows/configure.yml new file mode 100644 index 0000000..45c9d3c --- /dev/null +++ b/.github/workflows/configure.yml @@ -0,0 +1,38 @@ +name: ⚙ Configure cloud app + +on: + workflow_dispatch: + inputs: + secret: + description: 'Admin secret' + type: string + default: '' + required: true + discord_bot_token: + description: 'Discord bot token' + type: string + default: '' + telegram_bot_token: + description: 'Telegram bot token' + type: string + default: '' + steam_web_api_key: + description: 'Steam web API key' + type: string + default: '' + +jobs: + configure: + name: 🛬 Create/update the secrets and env vars + runs-on: ubuntu-latest + + steps: + - uses: superfly/flyctl-actions/setup-flyctl@master + - name: 🛩 Update on fly.io + run: | + flyctl secrets set SECRET=${{ secrets.SECRET }} --app ${{ github.repository_owner }}-gsw + flyctl secrets set DISCORD_BOT_TOKEN=${{ secrets.DISCORD_BOT_TOKEN }} --app ${{ github.repository_owner }}-gsw + flyctl secrets set TELEGRAM_BOT_TOKEN=${{ secrets.TELEGRAM_BOT_TOKEN }} --app ${{ github.repository_owner }}-gsw + flyctl secrets set STEAM_WEB_API_KEY=${{ secrets.STEAM_WEB_API_KEY }} --app ${{ github.repository_owner }}-gsw + env: + FLY_API_TOKEN: ${{ secrets.FLY_API_TOKEN }} diff --git a/.github/workflows/create.yml b/.github/workflows/create.yml new file mode 100644 index 0000000..93208bf --- /dev/null +++ b/.github/workflows/create.yml @@ -0,0 +1,18 @@ +name: 🏗 Create cloud app + +on: + workflow_dispatch: + +jobs: + create: + name: 🛫 Create the app and volume entries + runs-on: ubuntu-latest + + steps: + - uses: superfly/flyctl-actions/setup-flyctl@master + - name: 🛩 Create on fly.io + run: | + flyctl apps create ${{ github.repository_owner }}-gsw + flyctl volumes create gsw_data --region ${{ secrets.FLY_REGION }} --size 1 + env: + FLY_API_TOKEN: ${{ secrets.FLY_API_TOKEN }} diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 61d0dce..0ac537d 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -2,20 +2,23 @@ name: ☁️ Deploy to the cloud on: workflow_dispatch: - # push: - # branches: - # - master + push: + branches: + - master jobs: - push: + deploy: + name: 🚀 Deploy app runs-on: ubuntu-latest + steps: - - name: 🚚 Get latest code - uses: actions/checkout@v2 + - uses: actions/checkout@v3 + name: 🚚 Get latest code with: fetch-depth: 0 - - name: 🐙 Add new remote, and push to master - run: | - git remote add cloudrepo ${{ secrets.CLOUD_REPO_URL }} - git push -f cloudrepo ${{ github.ref_name }}:master + - uses: superfly/flyctl-actions/setup-flyctl@master + - name: 🛩 Deploy to fly.io + run: flyctl deploy --remote-only --auto-confirm --region ${{ secrets.FLY_REGION }} --app ${{ github.repository_owner }}-gsw --env + env: + FLY_API_TOKEN: ${{ secrets.FLY_API_TOKEN }} diff --git a/.gitignore b/.gitignore index bfb705e..50bccd9 100644 --- a/.gitignore +++ b/.gitignore @@ -5,6 +5,7 @@ logs npm-debug.log* yarn-debug.log* yarn-error.log* +.vscode # Diagnostic reports (https://nodejs.org/api/report.html) report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json diff --git a/.nvmrc b/.nvmrc index ec101ca..d928989 100644 --- a/.nvmrc +++ b/.nvmrc @@ -1 +1 @@ -12.20.1 +16.15.1 diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..8812233 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,34 @@ +FROM debian:bullseye as builder + +ARG NODE_VERSION=16.15.1 + +RUN apt-get update; apt install -y curl python-is-python3 pkg-config build-essential +RUN curl https://get.volta.sh | bash +ENV VOLTA_HOME /root/.volta +ENV PATH /root/.volta/bin:$PATH +RUN volta install node@${NODE_VERSION} + +####################################################################### + +RUN mkdir /app +WORKDIR /app + +COPY . . + +RUN npm install --production=false && npm run build +RUN rm -rf node_modules && npm install --production=true + +####################################################################### + +FROM debian:bullseye + +LABEL fly_launch_runtime="nodejs" + +COPY --from=builder /root/.volta /root/.volta +COPY --from=builder /app /app + +WORKDIR /app +ENV NODE_ENV production +ENV PATH /root/.volta/bin:$PATH + +CMD [ "npm", "run", "start" ] diff --git a/fly.toml b/fly.toml new file mode 100644 index 0000000..1520977 --- /dev/null +++ b/fly.toml @@ -0,0 +1,46 @@ +app = "game-server-watcher" + +kill_signal = "SIGINT" +kill_timeout = 5 +processes = [] + +[env] + DBG=0 + REFRESH_TIME_MINUTES=2 + DATA_PATH = /data/ + +[mounts] + source="gsw_data" + destination="/data" + +[experimental] + auto_rollback = true + allowed_public_ports = [] + # cmd = ["node", "--max-old-space-size=180", "server.js"] + +[[services]] + http_checks = [] + internal_port = 8080 + processes = ["app"] + protocol = "tcp" + script_checks = [] + + [services.concurrency] + hard_limit = 25 + soft_limit = 20 + type = "connections" + + [[services.ports]] + force_https = true + handlers = ["http"] + port = 80 + + [[services.ports]] + handlers = ["tls", "http"] + port = 443 + + [[services.tcp_checks]] + grace_period = "1s" + interval = "15s" + restart_limit = 0 + timeout = "2s"