diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index 2691cb2..34ca976 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -53,6 +53,8 @@ jobs: push: ${{ env.SHOULD_PUSH_IMAGE }} tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} + secrets: | + "ip2location-token=${{ secrets.IP2LOCATION_TOKEN }}" cache-from: type=gha cache-to: type=gha,mode=max @@ -97,5 +99,7 @@ jobs: push: ${{ env.SHOULD_PUSH_IMAGE }} tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} + secrets: | + "ip2location-token=${{ secrets.IP2LOCATION_TOKEN }}" cache-from: type=gha cache-to: type=gha,mode=max diff --git a/Dockerfile b/Dockerfile index 53811ab..4e48ff4 100644 --- a/Dockerfile +++ b/Dockerfile @@ -27,8 +27,9 @@ RUN --mount=type=bind,source=package.json,target=package.json \ npm ci COPY . . -RUN npm run build +RUN --mount=type=secret,id=ip2location-token,env=PN_ACT_CONFIG_IP2LOCATION_TOKEN \ + npm run build # * Running the final application FROM base AS final diff --git a/package.json b/package.json index e8e6ba8..7d0c32b 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,8 @@ "scripts": { "lint": "eslint .", "lint:fix": "eslint --fix .", - "build": "npm run lint && npm run clean && npx tsc && npx tsc-alias && npm run copy-static && node ./scripts/download-ip2location-databases.js", + "download-geoip-db": "node ./scripts/download-ip2location-databases.js", + "build": "npm run lint && npm run clean && npx tsc && npx tsc-alias && npm run copy-static && npm run download-geoip-db", "clean": "rimraf ./dist", "copy-static": "copyfiles -e \"src/**/*.ts\" -u 1 \"src/**/*\" dist", "start": "node .", @@ -87,4 +88,4 @@ "ndarray": "^1.0.19", "typescript": "^4.9.5" } -} +} \ No newline at end of file diff --git a/scripts/download-ip2location-databases.js b/scripts/download-ip2location-databases.js index 4a01a97..3a45616 100644 --- a/scripts/download-ip2location-databases.js +++ b/scripts/download-ip2location-databases.js @@ -18,12 +18,15 @@ const databases = { async function main() { if (!process.env.PN_ACT_CONFIG_IP2LOCATION_TOKEN) { - // * Optional + console.warn('IP2Location token not found in environment variables. Skipping database download.'); return; } + console.log(`Downloading ${Object.keys(databases).length} IP2Location databases...`); + for (const name in databases) { const database = databases[name]; + console.log(`Downloading ${database.file_name}...`); const response = await fetch(`https://www.ip2location.com/download/?token=${process.env.PN_ACT_CONFIG_IP2LOCATION_TOKEN}&file=${name}`); const arrayBuffer = await response.arrayBuffer(); const buffer = Buffer.from(arrayBuffer);