Skip to content

Commit

Permalink
feat: new server migration
Browse files Browse the repository at this point in the history
  • Loading branch information
SrIzan10 committed Oct 19, 2023
1 parent 6364205 commit a373f04
Show file tree
Hide file tree
Showing 6 changed files with 107 additions and 37 deletions.
54 changes: 54 additions & 0 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.

# GitHub recommends pinning actions to a commit SHA.
# To get a newer version, you will need to update the SHA.
# You can also reference a tag or branch, but the action may change without warning.

name: Publish Docker image

on:
push:
branches:
- main

jobs:
push_to_registry:
name: Push Docker image to Docker Hub
runs-on: ubuntu-latest
steps:
- name: Check out the repo
uses: actions/checkout@v3

- name: Log in to Sr Izan's container registry
uses: docker/login-action@f4ef78c080cd8ba55a85445d5b36e214a81df20a
with:
registry: containers.srizan.dev
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}

- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7
with:
images: containers.srizan.dev/sernlinear
tags: latest

- name: Build and push Docker image
uses: docker/build-push-action@3b5e8027fcad23fda98b2e3ac259d8d67585f671
with:
context: .
file: ./Dockerfile
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}

- name: Emit a webhook to the server
env:
AUTH_HEADER: ${{ secrets.WHSERVER_TOKEN }}
run: |
curl -X POST \
-H "Authorization: Bearer $AUTH_HEADER" \
https://webhooks.srizan.dev/hooks/sernlinear
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
node_modules/
.env
.env
dist/
21 changes: 14 additions & 7 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
FROM node:alpine
# Build stage
FROM node:lts-alpine AS build

WORKDIR /app

COPY package.json ./

RUN npm install
COPY package.json yarn.lock ./
RUN yarn

COPY . .
RUN yarn build

# Final stage
FROM node:lts-alpine AS final

WORKDIR /app

RUN npm i -g typescript
RUN tsc --build
COPY --from=build /app/dist ./dist
COPY --from=build /app/node_modules ./node_modules
COPY --from=build /app/package.json ./package.json

CMD node dist/index.js
CMD ["node", "dist/index.js"]
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@
"license": "UNLICENSED",
"dependencies": {
"@linear/sdk": "^6.0.0",
"@sern/handler": "alpha",
"@sern/handler": "^3.1.0",
"dayjs": "^1.11.9",
"discord.js": "latest",
"discord.js": "^14.11.0",
"dotenv": "^16.3.1"
},
"devDependencies": {
"@types/node": "^17.0.25",
"typescript": "5.0"
"typescript": "^5.2.2"
},
"type": "module"
}
32 changes: 20 additions & 12 deletions src/plugins/publish.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// @ts-nocheck
/**
* This is publish plugin, it allows you to publish your application commands using the discord.js library with ease.
* @plugin
* [DEPRECATED] It allows you to publish your application commands using the discord.js library with ease.
*
* @author @EvolutionX-10 [<@697795666373640213>]
* @version 2.0.0
Expand All @@ -16,14 +17,15 @@
* }
* })
* ```
* @end
*/
import {
CommandInitPlugin,
CommandType,
controller,
SernOptionsData,
Service,
SlashCommand,
Service,
} from "@sern/handler";
import {
ApplicationCommandData,
Expand All @@ -44,11 +46,17 @@ export function publish<
| CommandType.Both
| CommandType.Slash
| CommandType.CtxMsg
| CommandType.CtxUser
| CommandType.CtxUser,
>(options?: PublishOptions) {
return CommandInitPlugin<T>(async ({ module }) => {
// Users need to provide their own useContainer function.
const client = Service("@sern/client");
let client;
try {
client = (await import("@sern/handler")).Service("@sern/client");
} catch {
const { useContainer } = await import("../index.js");
client = useContainer("@sern/client")[0];
}
const defaultOptions = {
guildIds: [],
dmPermission: undefined,
Expand Down Expand Up @@ -90,7 +98,7 @@ export function publish<
description: cmd(module.description, ""),
options: cmd(
optionsTransformer((module as SlashCommand).options ?? []),
[]
[],
),
defaultMemberPermissions,
dmPermission,
Expand All @@ -102,17 +110,17 @@ export function publish<

if (!guildIds.length) {
const cmd = (await client.application!.commands.fetch()).find(
(c) => c.name === module.name && c.type === curAppType
(c) => c.name === module.name && c.type === curAppType,
);
if (cmd) {
if (!cmd.equals(commandData, true)) {
logged(
`Found differences in global command ${module.name}`
`Found differences in global command ${module.name}`,
);
cmd.edit(commandData).then(
log(
`${module.name} updated with new data successfully!`
)
`${module.name} updated with new data successfully!`,
),
);
}
return controller.next();
Expand All @@ -128,7 +136,7 @@ export function publish<
const guild = await client.guilds.fetch(id).catch(c);
if (!guild) continue;
const guildCmd = (await guild.commands.fetch()).find(
(c) => c.name === module.name && c.type === curAppType
(c) => c.name === module.name && c.type === curAppType,
);
if (guildCmd) {
if (!guildCmd.equals(commandData, true)) {
Expand All @@ -137,8 +145,8 @@ export function publish<
.edit(commandData)
.then(
log(
`${module.name} updated with new data successfully!`
)
`${module.name} updated with new data successfully!`,
),
)
.catch(c);
continue;
Expand Down
28 changes: 14 additions & 14 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -93,14 +93,14 @@
resolved "https://registry.yarnpkg.com/@sapphire/snowflake/-/snowflake-3.5.1.tgz#254521c188b49e8b2d4cc048b475fb2b38737fec"
integrity sha512-BxcYGzgEsdlG0dKAyOm0ehLGm2CafIrfQTZGWgkfKYbj+pNNsorZ7EotuZukc2MT70E0UbppVbtpBrqpzVzjNA==

"@sern/handler@alpha":
version "3.0.0-rc10"
resolved "https://registry.yarnpkg.com/@sern/handler/-/handler-3.0.0-rc10.tgz#bcf476c39a3e43d6da1c1bbee1517fc98312542e"
integrity sha512-bBlQ5zRkyk0oZUCc9pnJec1i0+yh3/bFBalOdGI9bPV+03bYhxOS4N95jpANn0cVo44p82N/nqQHo8wdfN3luA==
"@sern/handler@^3.1.0":
version "3.1.0"
resolved "https://registry.yarnpkg.com/@sern/handler/-/handler-3.1.0.tgz#222f84076b9eb78b136dd71ed7b476d273629b64"
integrity sha512-idan6m4h6hQEkqBrne92IPgVnUtOlxHRrn0GqYOfwXaWGmPKnQWbT/lVzx3ytDRXQWoTrubZnF12r5XGS30Znw==
dependencies:
iti "^0.6.0"
rxjs "^7.8.0"
ts-results-es "^3.6.0"
ts-results-es "^4.0.0"

"@tokenizer/token@^0.3.0":
version "0.3.0"
Expand Down Expand Up @@ -146,7 +146,7 @@ discord-api-types@^0.37.41:
resolved "https://registry.yarnpkg.com/discord-api-types/-/discord-api-types-0.37.48.tgz#347907bce8f3c00e746b2a7afcf98628d7065731"
integrity sha512-vu2NQJD7SZRjpKDC2DPNsxTz34KS53OrotA+LGRW6mcyT55Hjqu66aRrouzjYhea7tllL9I7rvWVX7bg3aT2AQ==

discord.js@latest:
discord.js@^14.11.0:
version "14.11.0"
resolved "https://registry.yarnpkg.com/discord.js/-/discord.js-14.11.0.tgz#6529d49f30d10fc5a9ff8e6796661aa998769afe"
integrity sha512-CkueWYFQ28U38YPR8HgsBR/QT35oPpMbEsTNM30Fs8loBIhnA4s70AwQEoy6JvLcpWWJO7GY0y2BUzZmuBMepQ==
Expand Down Expand Up @@ -303,20 +303,20 @@ ts-mixer@^6.0.3:
resolved "https://registry.yarnpkg.com/ts-mixer/-/ts-mixer-6.0.3.tgz#69bd50f406ff39daa369885b16c77a6194c7cae6"
integrity sha512-k43M7uCG1AkTyxgnmI5MPwKoUvS/bRvLvUb7+Pgpdlmok8AoqmUaZxUUw8zKM5B1lqZrt41GjYgnvAi0fppqgQ==

ts-results-es@^3.6.0:
version "3.6.0"
resolved "https://registry.yarnpkg.com/ts-results-es/-/ts-results-es-3.6.0.tgz#351023246249ef558c2fe3700099e1535226ce47"
integrity sha512-swha7PpeUNX93LzwhNtlk97FZZdTkCsI4j2ShletEmQ4cEi9SWy95x8XRTpfOP8gr16ikEBSi4U8xD43BYHDFg==
ts-results-es@^4.0.0:
version "4.0.0"
resolved "https://registry.yarnpkg.com/ts-results-es/-/ts-results-es-4.0.0.tgz#0116b1121c6c6e1b892009983048efb2be0744ff"
integrity sha512-v8vi0R4hu3Z5CugRPGA2qnIns4a4j+3/Bkh5Iak041AsBNOYA6DNjoijvHDli76Grt6KvihU6errHX03Fz9Jzw==

tslib@^2.1.0, tslib@^2.5.0:
version "2.6.0"
resolved "https://registry.yarnpkg.com/tslib/-/tslib-2.6.0.tgz#b295854684dbda164e181d259a22cd779dcd7bc3"
integrity sha512-7At1WUettjcSRHXCyYtTselblcHl9PJFFVKiCAy/bY97+BPZXSQ2wbq0P9s8tK2G7dFQfNnlJnPAiArVBVBsfA==

typescript@5.0:
version "5.0.4"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-5.0.4.tgz#b217fd20119bd61a94d4011274e0ab369058da3b"
integrity sha512-cW9T5W9xY37cc+jfEnaUvX91foxtHkza3Nw3wkoF4sSlKn0MONdkdEndig/qPBWXNkmplh3NzayQzCiHM4/hqw==
typescript@^5.2.2:
version "5.2.2"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-5.2.2.tgz#5ebb5e5a5b75f085f22bc3f8460fba308310fa78"
integrity sha512-mI4WrpHsbCIcwT9cF4FZvr80QUeKvsUsUvKDoR+X/7XHQH98xYD8YHZg7ANtz2GtZt/CBq2QJ0thkGJMHfqc1w==

undici@^5.22.0:
version "5.22.1"
Expand Down

0 comments on commit a373f04

Please sign in to comment.