Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(server): fix version parsing #1586

Merged
merged 4 commits into from
Sep 3, 2024
Merged

fix(server): fix version parsing #1586

merged 4 commits into from
Sep 3, 2024

Conversation

sbruens
Copy link
Contributor

@sbruens sbruens commented Aug 30, 2024

#1535 changed how we build the Shadowbox server image. Nothing is setting the SB_VERSION environment variable that the webpack config parses to determine the server's version.

task shadowbox:docker:start IMAGE_VERSION="1.1.1"

This now sets the correct version again:

curl --insecure https://[::]:8081/TestApiPrefix/server | jq
{
   ...
  "version": "1.1.1",
   ...
}

@@ -31,7 +31,9 @@ const config = {
},
plugins: [
// Used by server/version.ts.
process.env.SB_VERSION ? new webpack.DefinePlugin({'__VERSION__': JSON.stringify(process.env.SB_VERSION)}): undefined,
process.env.VERSION
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The fix is OK, but I worry that such a generic env var may collide with other things running on the developer's machine, causing accidental injection.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think your interpretation of the Task change is wrong. We are not using an environment variable at all. We have a Task VERSION variable that gets interpolated in the command. There's no env VAR for VERSION. we set the docker --build-arg flag.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I meant that the webpack build step is reading from an environment variable (process.env.X), but we stopped providing it in our Docker build.

But I was wrong about VERSION being available. It was working for me locally, but maybe I polluted my env while testing the build stages. I also just noticed that the build arg is in the wrong place anyway. It needs to be inside the FROM build stage to be usable, which is causing the label to not be set.

PTAL. I'm changing the Node.js env name back to SB_VERSION and set it as an ENV variable for the Node.js build step. I think that's the correct solution.

By the way, what does ${BUILD_ENV:+--mode="${BUILD_ENV} do on the npx webpack line? I can't find any references to it.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a bash expansion that expands only if BUILD_ENV is defined. That's because we need it to expand to a --mode= flag.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah it's https://webpack.js.org/configuration/mode/? For some reason I couldn't find it. Thanks.

@sbruens sbruens requested a review from fortuna August 30, 2024 21:30
@@ -31,7 +31,9 @@ const config = {
},
plugins: [
// Used by server/version.ts.
process.env.SB_VERSION ? new webpack.DefinePlugin({'__VERSION__': JSON.stringify(process.env.SB_VERSION)}): undefined,
process.env.VERSION
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a bash expansion that expands only if BUILD_ENV is defined. That's because we need it to expand to a --mode= flag.

@@ -91,7 +94,7 @@ tasks:
cmds:
- rm -rf '{{.IMAGE_ROOT}}'
- mkdir -p '{{.IMAGE_ROOT}}'
- {task: build, vars: {TARGET_OS: linux, TARGET_ARCH: '{{.TARGET_ARCH}}', TARGET_DIR: '{{joinPath .IMAGE_ROOT "/opt/outline-server"}}'}}
- {task: build, vars: {SB_VERSION: '{{.VERSION}}', TARGET_OS: linux, TARGET_ARCH: '{{.TARGET_ARCH}}', TARGET_DIR: '{{joinPath .IMAGE_ROOT "/opt/outline-server"}}'}}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use VERSION for task variables.

src/shadowbox/Taskfile.yml Outdated Show resolved Hide resolved
src/shadowbox/Taskfile.yml Outdated Show resolved Hide resolved
@sbruens sbruens merged commit fa3d7c5 into master Sep 3, 2024
11 checks passed
@sbruens sbruens deleted the sbruens/fix-server branch September 3, 2024 18:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants