add Docker build and push scripts; update versioning and environment configuration
This commit is contained in:
parent
a19070c767
commit
e2709541ba
3
.gitignore
vendored
3
.gitignore
vendored
@ -1,4 +1,5 @@
|
||||
node_modules
|
||||
data
|
||||
*.code-workspace
|
||||
.vscode
|
||||
.vscode
|
||||
.env
|
||||
58
build.docker.image.sh
Normal file
58
build.docker.image.sh
Normal file
@ -0,0 +1,58 @@
|
||||
#!/bin/bash
|
||||
|
||||
# --- Configuration ---
|
||||
IMAGE_NAME="172.22.102.100:40016/team-mmkb/simple-http-upload"
|
||||
PACKAGE_JSON="package.json"
|
||||
|
||||
# --- Functions ---
|
||||
|
||||
# Function to get the current version from package.json
|
||||
get_current_version() {
|
||||
if [ ! -f "$PACKAGE_JSON" ]; then
|
||||
echo "Error: $PACKAGE_JSON not found."
|
||||
exit 1
|
||||
fi
|
||||
jq -r '.version' "$PACKAGE_JSON"
|
||||
}
|
||||
|
||||
# Function to increment the major version
|
||||
increment_major_version() {
|
||||
local current_version="$1"
|
||||
local major=$(echo "$current_version" | cut -d'.' -f1)
|
||||
local minor=$(echo "$current_version" | cut -d'.' -f2)
|
||||
local patch=$(echo "$current_version" | cut -d'.' -f3)
|
||||
|
||||
minor=$((minor + 1))
|
||||
echo "$major.$minor.$patch"
|
||||
}
|
||||
|
||||
# Function to update the package.json with the new version
|
||||
update_package_json() {
|
||||
local new_version="$1"
|
||||
jq ".version = \"$new_version\"" "$PACKAGE_JSON" > temp.json && mv temp.json "$PACKAGE_JSON"
|
||||
}
|
||||
|
||||
# --- Main Script ---
|
||||
|
||||
# Get the current version
|
||||
current_version=$(get_current_version)
|
||||
echo "Current version: $current_version"
|
||||
|
||||
# Increment the major version
|
||||
new_version=$(increment_major_version "$current_version")
|
||||
echo "New version: $new_version"
|
||||
|
||||
# Update package.json
|
||||
update_package_json "$new_version"
|
||||
echo "Updated $PACKAGE_JSON with version: $new_version"
|
||||
|
||||
# Build the Docker image with the new version
|
||||
docker build -t "$IMAGE_NAME:$new_version" .
|
||||
if [ $? -eq 0 ]; then
|
||||
echo "Docker image built successfully: $IMAGE_NAME:$new_version"
|
||||
else
|
||||
echo "Error building docker image"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "Done!"
|
||||
16
index.js
16
index.js
@ -1,3 +1,4 @@
|
||||
require('dotenv').config()
|
||||
const express = require('express');
|
||||
const fileUpload = require('express-fileupload');
|
||||
const fs = require('fs');
|
||||
@ -6,9 +7,11 @@ const app = express();
|
||||
const port = 3000;
|
||||
|
||||
const uploadPath = process.env.UPLOAD_PATH || '/tmp';
|
||||
// const config = process.env.CONFIG || "{ \"uploadGroups\": [] }";
|
||||
const config = process.env.CONFIG || "{ \"uploadGroups\": [] }";
|
||||
//const config = process.env.CONFIG || "{ \"uploadGroups\": [{ \"matcher\": \"^mmkb-android-.*-test\\.apk$\", \"groupSize\": 3},{ \"matcher\": \"^mmkb-android-.*-int\\.apk$\", \"groupSize\": 3},{ \"matcher\": \"^mmkb-android-.*-prod\\.apk$\", \"groupSize\": 3}] }";
|
||||
|
||||
console.info("Upload path: ", uploadPath);
|
||||
console.info("Config: ", config);
|
||||
|
||||
|
||||
app.use(fileUpload());
|
||||
@ -48,14 +51,16 @@ const processGroups = () => {
|
||||
* clean up files based on the group size
|
||||
*/
|
||||
const cleanUp = () => {
|
||||
console.info("Cleaning up files...");
|
||||
const groups = processGroups();
|
||||
console.info("Groups: ", groups);
|
||||
|
||||
groups.forEach(group => {
|
||||
if (group.files.length > group.groupSize) {
|
||||
const filesToDelete = group.files.slice(0, group.files.length - group.groupSize);
|
||||
filesToDelete.forEach(file => {
|
||||
console.log(new Date().toISOString() + " Deleting file: ", file);
|
||||
fs.unlinkSync(uploadPath + "/" + file);
|
||||
//fs.unlinkSync(uploadPath + "/" + file);
|
||||
});
|
||||
}
|
||||
});
|
||||
@ -104,6 +109,13 @@ app.get('/state', (req, res) => {
|
||||
res.send(groups);
|
||||
});
|
||||
|
||||
app.get('/clean', (req, res) => {
|
||||
cleanUp();
|
||||
|
||||
res.setHeader('Content-Type', 'application/json');
|
||||
res.send('Clean up done!');
|
||||
});
|
||||
|
||||
app.get('/', (req, res) => {
|
||||
const files = [];
|
||||
fs.readdirSync(uploadPath).forEach(file => {
|
||||
|
||||
17
package-lock.json
generated
17
package-lock.json
generated
@ -1,14 +1,15 @@
|
||||
{
|
||||
"name": "simple-http-file-api",
|
||||
"version": "1.0.0",
|
||||
"version": "1.1.0",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "simple-http-file-api",
|
||||
"version": "1.0.0",
|
||||
"version": "1.1.0",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"dotenv": "^16.4.7",
|
||||
"express": "^4.21.2",
|
||||
"express-fileupload": "^1.5.1",
|
||||
"mime": "^4.0.6"
|
||||
@ -170,6 +171,18 @@
|
||||
"npm": "1.2.8000 || >= 1.4.16"
|
||||
}
|
||||
},
|
||||
"node_modules/dotenv": {
|
||||
"version": "16.4.7",
|
||||
"resolved": "https://registry.npmjs.org/dotenv/-/dotenv-16.4.7.tgz",
|
||||
"integrity": "sha512-47qPchRCykZC03FhkYAhrvwU4xDBFIj1QPqaarj6mdM/hgUzfPHcpkHJOn3mJAufFeeAxAzeGsr5X0M4k6fLZQ==",
|
||||
"license": "BSD-2-Clause",
|
||||
"engines": {
|
||||
"node": ">=12"
|
||||
},
|
||||
"funding": {
|
||||
"url": "https://dotenvx.com"
|
||||
}
|
||||
},
|
||||
"node_modules/dunder-proto": {
|
||||
"version": "1.0.1",
|
||||
"resolved": "https://registry.npmjs.org/dunder-proto/-/dunder-proto-1.0.1.tgz",
|
||||
|
||||
@ -1,15 +1,18 @@
|
||||
{
|
||||
"name": "simple-http-file-api",
|
||||
"version": "1.0.0",
|
||||
"version": "1.1.0",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"start": "node index.js",
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
"test": "echo \"Error: no test specified\" && exit 1",
|
||||
"docker.build.image": "bash ./build.docker.image.sh",
|
||||
"docker.push.image": "bash ./push.docker.image.sh"
|
||||
},
|
||||
"author": "",
|
||||
"license": "ISC",
|
||||
"description": "",
|
||||
"dependencies": {
|
||||
"dotenv": "^16.4.7",
|
||||
"express": "^4.21.2",
|
||||
"express-fileupload": "^1.5.1",
|
||||
"mime": "^4.0.6"
|
||||
|
||||
7
push.docker.image.sh
Normal file
7
push.docker.image.sh
Normal file
@ -0,0 +1,7 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Get the current version from package.json
|
||||
VERSION=$(jq -r '.version' package.json)
|
||||
|
||||
# Build the Docker image with the updated version from package.json
|
||||
docker push 172.22.102.100:40016/team-mmkb/simple-http-upload:$VERSION
|
||||
Loading…
Reference in New Issue
Block a user