Skip to content

Commit

Permalink
test secret var update in docker image
Browse files Browse the repository at this point in the history
  • Loading branch information
jancimertel committed Sep 15, 2024
1 parent ecfc5ac commit af1976f
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 5 deletions.
9 changes: 8 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,11 @@ COPY --from=build-env /app /app

WORKDIR /app/server

CMD ["pnpm", "start:dist"]
RUN BUILD_TIMESTAMP=$(date +'%a %d.%m.%Y %H:%M') && \
echo "Build Timestamp during build: $BUILD_TIMESTAMP" && \
echo "BUILD_TIMESTAMP=\"$BUILD_TIMESTAMP\"" > /app/server/.build_env

RUN echo "source /app/server/.build_env" >> /etc/profile

CMD ["/bin/sh", "-c", "source /app/server/.build_env && pnpm start:dist -- \"$BUILD_TIMESTAMP\""]

9 changes: 8 additions & 1 deletion Dockerfile.cached
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,11 @@ COPY --from=build-env /app/server/secret /app/server/secret
COPY --from=build-env /app/server/package.json /app/server/package.json

WORKDIR /app/server
CMD ["pnpm", "start:dist"]

RUN BUILD_TIMESTAMP=$(date +'%a %d.%m.%Y %H:%M') && \
echo "Build Timestamp during build: $BUILD_TIMESTAMP" && \
echo "BUILD_TIMESTAMP=\"$BUILD_TIMESTAMP\"" > /app/server/.build_env

RUN echo "source /app/server/.build_env" >> /etc/profile

CMD ["/bin/sh", "-c", "source /app/server/.build_env && pnpm start:dist -- \"$BUILD_TIMESTAMP\""]
15 changes: 12 additions & 3 deletions packages/server/src/common/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,15 @@ export function checkPassword(

const defaultJwtAlgo = "HS256";

let secret = (process.env.SECRET as string) || "";
if (process.argv.length > 3) {
secret += process.argv[3];
} else if (process.env.BUILD_TIMESTAMP) {
secret += process.env.BUILD_TIMESTAMP;
}

console.log(`SECRET set to ${secret}`);

/**
* Function thats creates signed jwt token for user
* @param user
Expand All @@ -58,7 +67,7 @@ export function generateAccessToken(user: IUser, expDays = 30): string {
user,
exp: Math.floor(Date.now() / 1000) + 86400 * expDays,
},
process.env.SECRET as string,
secret,
{
algorithm: defaultJwtAlgo,
}
Expand All @@ -72,11 +81,11 @@ export function generateAccessToken(user: IUser, expDays = 30): string {
*/
export function validateJwt() {
return expressjwt({
secret: process.env.SECRET || "",
secret: secret,
algorithms: [defaultJwtAlgo],
requestProperty: "user",
isRevoked: async (req, tokenn) => {
return false
return false;
},
getToken: (req: Request): string | Promise<string> | undefined => {
if (
Expand Down
9 changes: 9 additions & 0 deletions packages/server/src/settings.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
import dotenv from "dotenv";
const fs = require("fs");
const path = require("path");

// try the build env vars first
console.log(
dotenv.config({
path: `.build_env`,
})
);

// will load .env.${ENV_FILE} if set
if (process.env.ENV_FILE) {
Expand Down

0 comments on commit af1976f

Please sign in to comment.