Skip to content

Commit 4030d51

Browse files
optimized android build in docker
1 parent 707185c commit 4030d51

2 files changed

Lines changed: 26 additions & 13 deletions

File tree

Dockerfile

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -64,20 +64,23 @@ COPY package.json package-lock.json* ./
6464
RUN npm ci --omit=dev
6565

6666
# Pre-cache Capacitor dependencies for Android builds
67-
RUN mkdir -p /tmp/capacitor-cache && \
68-
cd /tmp/capacitor-cache && \
67+
RUN mkdir -p dist/capacitor-cache && \
68+
cd dist/capacitor-cache && \
6969
echo '{"dependencies":{"@capacitor/cli":"^8.0.0","@capacitor-community/text-to-speech":"git+https://github.com/capacitor-community/text-to-speech.git#v8.0.0","@capacitor/android":"^8.0.0","@capacitor/assets":"^3.0.5","@capacitor/core":"^8.0.0"}}' > package.json && \
7070
npm install && \
71-
cd / && \
72-
rm -rf /tmp/capacitor-cache
71+
echo "import type { CapacitorConfig } from '@capacitor/cli'; const config: CapacitorConfig = { appId: 'io.liascript.course', appName: 'App', webDir: 'www' }; export default config;" > capacitor.config.ts && \
72+
mkdir -p www && \
73+
touch www/index.html && \
74+
npx cap add android && \
75+
cd android && \
76+
./gradlew && \
77+
cd .. && \
78+
rm -rf www android capacitor.config.ts && \
79+
cd ..
7380

7481
# Copy the dist folder
7582
COPY dist/ ./dist/
7683

77-
# Create symlink for server public folder at expected path
78-
RUN mkdir -p /app/liascript-exporter/server && \
79-
ln -s /app/dist/server/public /app/liascript-exporter/server/public
80-
8184
# Install Puppeteer's Chrome explicitly
8285
RUN npx puppeteer browsers install chrome
8386

src/export/android.ts

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,16 @@ export async function exporter(argument: AndroidExportArguments, json: any) {
110110
})
111111
}
112112

113-
await helper.writeFile(
114-
path.join(tmp, 'package.json'),
115-
`{
113+
let capacitorCachePath = path.join(dirname, './capacitor-cache')
114+
if (fs.existsSync(capacitorCachePath)) {
115+
console.log('Using cached Capacitor dependencies for Android export')
116+
await fs.copy(capacitorCachePath, tmp)
117+
} else {
118+
capacitorCachePath = null
119+
120+
await helper.writeFile(
121+
path.join(tmp, 'package.json'),
122+
`{
116123
"scripts": {
117124
"build": "npx cap sync android"
118125
},
@@ -127,7 +134,8 @@ export async function exporter(argument: AndroidExportArguments, json: any) {
127134
"node": ">= 12"
128135
}
129136
}`,
130-
)
137+
)
138+
}
131139

132140
await helper.writeFile(
133141
path.join(tmp, 'capacitor.config.ts'),
@@ -170,7 +178,9 @@ export default config`,
170178

171179
execute(
172180
[
173-
'npm i',
181+
capacitorCachePath
182+
? 'echo "Using cached Capacitor dependencies"'
183+
: 'npm i',
174184
'npx cap add android',
175185
'npx cap sync',
176186
`npx @capacitor/assets generate --iconBackgroundColor '${argument['android-iconBackgroundColor'] || '#bbbbbb'}' --iconBackgroundColorDark '${argument['android-iconBackgroundColorDark'] || '#555555'}'`,

0 commit comments

Comments
 (0)