feat(bot): add dockerfile for JS rewrite, fix some loose ends (#210)

This commit is contained in:
41666 2021-04-03 17:53:05 -04:00 committed by GitHub
parent 7ec603cf70
commit 3190d41a9e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 23 additions and 32 deletions

View file

@ -1,4 +1,4 @@
FROM golang:1.15-alpine AS builder FROM node:14 AS builder
# Create the user and group files that will be used in the running container to # Create the user and group files that will be used in the running container to
# run the process as an unprivileged user. # run the process as an unprivileged user.
@ -6,41 +6,23 @@ RUN mkdir /user \
&& echo 'nobody:x:65534:65534:nobody:/:' >/user/passwd \ && echo 'nobody:x:65534:65534:nobody:/:' >/user/passwd \
&& echo 'nobody:x:65534:' >/user/group && echo 'nobody:x:65534:' >/user/group
# Install the Certificate-Authority certificates for the app to be able to make
# calls to HTTPS endpoints.
# Git is required for fetching the dependencies.
RUN apk add --no-cache ca-certificates git
# Set the working directory outside $GOPATH to enable the support for modules. # Set the working directory outside $GOPATH to enable the support for modules.
WORKDIR /src WORKDIR /src
# Fetch dependencies first; they are less susceptible to change on every build # Fetch dependencies first; they are less susceptible to change on every build
# and will therefore be cached for speeding up the next build # and will therefore be cached for speeding up the next build
COPY ./go.mod ./go.sum ./ COPY ./package.json ./yarn.lock /src/
RUN go mod download COPY ./packages/bot/package.json /src/packages/bot/
RUN yarn workspace @roleypoly/bot install --focus
# Import the code from the context. FROM node:14-slim AS final
COPY ./ ./ WORKDIR /src
# Build the executable to `/app`. Mark the build as statically linked.
RUN CGO_ENABLED=0 go build \
-installsuffix "static" \
-o /app ./src/discord-bot
# Final stage: the running container.
FROM scratch AS final
# Import the user and group files from the first stage.
COPY --from=builder /user/group /user/passwd /etc/ COPY --from=builder /user/group /user/passwd /etc/
# Import the Certificate-Authority certificates for enabling HTTPS.
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
# Import the compiled executable from the first stage.
COPY --from=builder /app /app
# Perform any further action as an unprivileged user.
USER nobody:nobody USER nobody:nobody
# Run the compiled binary. # Import the code from the context.
ENTRYPOINT ["/app"] COPY --from=builder /src/node_modules /src/node_modules
COPY ./packages/bot /src/packages/bot
ENTRYPOINT [ "node", "/src/packages/bot/index.js" ]

View file

@ -22,6 +22,11 @@ function messageEventListener(message) {
channel.send(`:beginner: Assign your roles here! ${appUrl}/s/${guildId}`); channel.send(`:beginner: Assign your roles here! ${appUrl}/s/${guildId}`);
} }
const client = new Client(); const client = new Client({
ws: {
intents: ['GUILDS', 'GUILD_MESSAGES'],
},
});
client.on('message', (message) => messageEventListener(message)); client.on('message', (message) => messageEventListener(message));
client.login(botToken); client.login(botToken);

View file

@ -5,5 +5,8 @@ const { ShardingManager } = require('discord.js');
const botToken = process.env['BOT_TOKEN']; const botToken = process.env['BOT_TOKEN'];
const manager = new ShardingManager('./bot.js', { token: botToken }); const manager = new ShardingManager(path.resolve(__dirname, 'bot.js'), {
token: botToken,
});
manager.spawn(); manager.spawn();

View file

@ -5,6 +5,7 @@
"start": "node index.js" "start": "node index.js"
}, },
"dependencies": { "dependencies": {
"discord.js": "^12.5.1" "discord.js": "^12.5.3",
"dotenv": "^8.2.0"
} }
} }