feat: add auto build

This commit is contained in:
Samuel N Cui
2023-09-26 15:23:23 +08:00
parent 5476e43aad
commit ad04a0dd9f
8 changed files with 24 additions and 142 deletions

View File

@@ -1,15 +1,15 @@
#!/usr/bin/env bash
set -ex;
set -e;
CURDIR=$(cd $(dirname $0); pwd);
cd ${CURDIR};
rm -rf output;
mkdir -p output;
go build -mod=vendor -o ./output/httpd ./cmd/tape-httpd;
go build -mod=vendor -o ./output/lto-info ./cmd/lto-info;
cp -r scripts ./output/;
cp -r ./frontend/dist ./output/frontend;
cp ./cmd/tape-httpd/tape-writer.service ./output/
cp ./cmd/tape-httpd/config.example.yaml ./output/
docker run --rm -v $(pwd):/app golang:1.21 sh -c "cd /app && bash build_backend.sh"
docker run --rm -v $(pwd):/app node:20-slim sh -c "cd /app && bash build_frontend.sh"

8
build_backend.sh Executable file
View File

@@ -0,0 +1,8 @@
#!/usr/bin/env bash
set -ex;
CURDIR=$(cd $(dirname $0); pwd);
cd ${CURDIR};
go build -o ./output/httpd ./cmd/tape-httpd;
go build -o ./output/lto-info ./cmd/lto-info;

12
build_frontend.sh Executable file
View File

@@ -0,0 +1,12 @@
#!/usr/bin/env bash
set -ex;
CURDIR=$(cd $(dirname $0); pwd);
cd ${CURDIR}/frontend;
export PNPM_HOME="/pnpm";
export PATH="$PNPM_HOME:$PATH";
corepack enable;
pnpm install;
pnpm run build;
cp -r ./dist ../output/frontend;

View File

@@ -1,7 +0,0 @@
#!/usr/bin/env bash
set -e;
CURDIR=$(cd $(dirname $0); pwd);
cd ${CURDIR};
docker run --rm -v $(pwd):/app golang:1.19 sh -c "cd /app && bash build.sh"

View File

@@ -1,38 +0,0 @@
package main
import (
"context"
"os"
"github.com/samuelncui/tapewriter/external"
"github.com/samuelncui/tapewriter/library"
"github.com/samuelncui/tapewriter/resource"
)
func main() {
ctx := context.Background()
db, err := resource.NewDBConn("sqlite", "./tapes.db")
if err != nil {
panic(err)
}
lib := library.New(db)
if err := lib.AutoMigrate(); err != nil {
panic(err)
}
file := os.Args[1]
barcode := os.Args[2]
name := os.Args[3]
f, err := os.Open(file)
if err != nil {
panic(err)
}
ext := external.New(lib)
if err := ext.ImportACPReport(ctx, barcode, name, "file:tape.key", f); err != nil {
panic(err)
}
}

View File

@@ -1,38 +0,0 @@
package main
import (
"context"
"os"
"github.com/samuelncui/tapewriter/external"
"github.com/samuelncui/tapewriter/library"
"github.com/samuelncui/tapewriter/resource"
)
func main() {
ctx := context.Background()
db, err := resource.NewDBConn("sqlite", "./tapes.db")
if err != nil {
panic(err)
}
lib := library.New(db)
if err := lib.AutoMigrate(); err != nil {
panic(err)
}
file := os.Args[1]
barcode := os.Args[2]
name := os.Args[3]
f, err := os.Open(file)
if err != nil {
panic(err)
}
ext := external.New(lib)
if err := ext.ImportACPReport(ctx, barcode, name, "file:tape.key", f); err != nil {
panic(err)
}
}

View File

@@ -1,45 +0,0 @@
#!/usr/bin/env bash
set -e;
POSITIONAL_ARGS=()
DEVICE="/dev/nst0"
SG_DEVICE=`sg_map | grep ${DEVICE} | awk '{print $1}'`
while [[ $# -gt 0 ]]; do
case $1 in
-s)
BARCODE="$2"
shift # past argument
shift # past value
;;
-n)
NAME="$2"
shift # past argument
shift # past value
;;
-*|--*)
echo "Unknown option $1"
exit 1
;;
*)
POSITIONAL_ARGS+=("$1") # save positional arg
shift # past argument
;;
esac
done
echo "format tape as number '$BARCODE', name '$NAME'"
echo "copy '${POSITIONAL_ARGS[@]}' to tape"
set -- "${POSITIONAL_ARGS[@]}"
set -ex;
stenc -f ${DEVICE} -e on -k /root/tape.key -a 1 --ckod
sleep 3
mkltfs -f -d ${SG_DEVICE} -s $BARCODE -n $NAME
sleep 3
ltfs -o devname=${SG_DEVICE} -o noatime -o sync_type=unmount -o work_directory=/opt/ltfs -o capture_index -o min_pool_size=256 -o max_pool_size=1024 -o eject /ltfs
sleep 3
acp --report /opt/ltfs/$BARCODE.json --to-linear $@ /ltfs/
sleep 3
umount /ltfs

View File

@@ -1,10 +0,0 @@
#!/usr/bin/env bash
set -e;
DEVICE="/dev/nst0"
SG_DEVICE=`sg_map | grep ${DEVICE} | awk '{print $1}'`
set -ex;
stenc -f ${DEVICE} -e on -k /root/tape.key -a 1 --ckod
ltfs -o devname=${SG_DEVICE} -o noatime -o sync_type=unmount -o work_directory=/opt/ltfs -o capture_index -o min_pool_size=256 -o max_pool_size=1024 -o eject /ltfs