Skip to content

Commit ce277e0

Browse files
committed
👷 minimize image size instead of using executable
1 parent b065707 commit ce277e0

File tree

9 files changed

+60
-17
lines changed

9 files changed

+60
-17
lines changed

.dockerignore

+2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ Dockerfile
88
.vscode
99
.editorconfig
1010

11+
node_modules/
12+
1113
README.md
1214

1315
/flag.txt

.github/workflows/docker.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,4 @@ jobs:
4747
with:
4848
name: build_exports.docker.${{ steps.export.outputs.BUILD_ID }}.${{ steps.export.outputs.BUILD_HASH }}
4949
path: output/
50-
retention-days: 1
50+
retention-days: 1

.github/workflows/test.yml

+17-2
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,21 @@ jobs:
2323
run: |
2424
timeout 5s bun run start || if [ $? -eq 124 ]; then exit 0; else exit 1; fi
2525
26+
build:
27+
name: Build
28+
runs-on: ubuntu-latest
29+
30+
steps:
31+
- uses: actions/checkout@v4
32+
33+
- uses: oven-sh/setup-bun@v2
34+
35+
- name: Install dependencies
36+
run: bun install
37+
38+
- name: Build
39+
run: bun run build
40+
2641
compile:
2742
name: Compile
2843
runs-on: ubuntu-latest
@@ -35,5 +50,5 @@ jobs:
3550
- name: Install dependencies
3651
run: bun install
3752

38-
- name: Test Compile
39-
run: bun run build
53+
- name: Compile
54+
run: bun run compile

Dockerfile

+8-4
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,15 @@ FROM oven/bun:1-alpine
1111
ENV FLAG=flag{test_flag}
1212
ENV NODE_ENV=production
1313

14-
RUN rm -rf /usr/local/bin/bun
14+
RUN adduser -D -h /home/ctf -s /bin/sh ctf
15+
WORKDIR /home/ctf
1516

16-
WORKDIR /app
17-
COPY --from=builder /app/dist/server /app/server
17+
COPY --from=builder /app/example.txt /home/ctf/example.txt
18+
COPY --from=builder /app/dist/index.js /usr/local/bin/ctf-server
19+
RUN chmod +x /usr/local/bin/ctf-server
20+
21+
USER ctf
1822

19-
CMD ["./server"]
23+
CMD ["/usr/local/bin/ctf-server"]
2024

2125
EXPOSE 3000

example.txt

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Hello World!
2+
3+
As you can see, something are replaced.
4+
5+
==> {nothing}
6+
7+
This is only an example.

package.json

+4-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@
66
"scripts": {
77
"start": "bun run ./src/index.ts",
88
"dev": "bun --watch run ./src/index.ts",
9-
"build": "bun build ./src/index.ts --compile --minify --outfile dist/server",
10-
"build:dev": "bun build ./src/index.ts --compile --sourcemap --outfile dist/server"
9+
"compile": "bun build ./src/index.ts --compile --minify --outfile dist/server",
10+
"compile:dev": "bun build ./src/index.ts --compile --sourcemap --outfile dist/server",
11+
"build": "bun build ./src/index.ts --target bun --minify --outdir dist/",
12+
"build:dev": "bun build ./src/index.ts --target bun --sourcemap --outdir dist/"
1113
},
1214
"keywords": [],
1315
"author": "",

src/index.html

+15-7
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818
.box {
1919
display: block;
2020
box-sizing: border-box;
21-
width: 500px;
22-
max-width: 95vw;
21+
width: 648px;
22+
max-width: 97vw;
2323
margin: 0 auto;
2424
padding: 20px;
2525
}
@@ -97,6 +97,14 @@
9797
::selection {
9898
background-color: rgba(61, 170, 194, .25);
9999
}
100+
101+
.w-100 {
102+
width: 100%;
103+
}
104+
105+
.w-75 {
106+
width: 75%;
107+
}
100108
</style>
101109
</head>
102110

@@ -107,10 +115,10 @@
107115
<span>sed</span>
108116
<span class="space"></span>
109117
<span>'s/{.*}/</span>
110-
<input type="text" name="pattern" placeholder="Enter text to replace">
118+
<input class="w-100" type="text" name="pattern" placeholder="replacement" value="truncated">
111119
<span>/g'</span>
112120
<span class="space"></span>
113-
<input type="text" name="file" placeholder="Enter file path">
121+
<input class="w-75" type="text" name="file" placeholder="file path" value="./example.txt">
114122
</div>
115123
<div class="output" id="output">Press enter to execute.</div>
116124
</div>
@@ -127,7 +135,7 @@
127135
const arrayBuffer = new Uint8Array(buf).buffer;
128136
return new TextDecoder().decode(arrayBuffer);
129137
}
130-
const tail = (s, c) => `${s}\nProcess exited with code ${c}.`;
138+
const tail = (s, t) => `${s}${s.endsWith('\n') ? '' : '\n'}\n${t}`;
131139
i.forEach(el => el.addEventListener('keydown', function (e) {
132140
if (e.keyCode !== 13) return;
133141
if (mutex) return;
@@ -147,9 +155,9 @@
147155
if (json.exit === 0) {
148156
setOutput(await debuffer(json.stdout), json.exit);
149157
} else {
150-
setOutput(tail(await debuffer(json.stderr), json.exit));
158+
setOutput(tail(await debuffer(json.stderr), `Process exited with code ${json.exit}.`));
151159
}
152-
} else throw new Error(await res.text());
160+
} else throw new Error(tail(await res.text(), `Server responded with status ${res.status}.`));
153161
}).catch(err => {
154162
setOutput(err.message);
155163
})

src/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/usr/bin/env -S bun run
1+
#!/usr/bin/env bun
22
import { $ } from 'bun';
33
import { readAndMinifyHTML } from './macro' with { type: 'macro' };
44

tsconfig.json

+5
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,10 @@
2525
"noPropertyAccessFromIndexSignature": false,
2626

2727
"forceConsistentCasingInFileNames": true,
28+
29+
"baseUrl": ".",
30+
"paths": {
31+
"@/*": ["src/*"]
32+
}
2833
}
2934
}

0 commit comments

Comments
 (0)