]> git.openfl.eu Git - yampl.git/commitdiff
add deploy script
authorFl_GUI <flor.guilini@hotmail.com>
Sun, 13 Apr 2025 16:30:19 +0000 (18:30 +0200)
committerFl_GUI <flor.guilini@hotmail.com>
Sun, 13 Apr 2025 16:30:19 +0000 (18:30 +0200)
Containerfile
compose.yaml
deploy.sh [new file with mode: 0755]
main.go

index 09bd2b5336c7bc1c7f42a43e57a87890fe8abb13..a0e70adcc6cd8b671e3d741a10061effcb903eb0 100644 (file)
@@ -6,7 +6,6 @@ COPY *.go .
 RUN go mod tidy
 
 RUN go install -ldflags="-s"
-RUN pwd
 
 # run image
 FROM scratch as run
index 2fb2a450959da95c660a3250c397aea4fcbaf430..9626b14b0dac2cfa49705d77b63556bfd88e2411 100644 (file)
@@ -3,7 +3,7 @@ services:
   yampl:
     image: yampl
     container_name: yampl
-    image: containers.openfl.eu/local/yampl:dev
+    image: ${IMAGE:-localhost/yampl:latest}
     build:
       dockerfile: Containerfile
     ports:
diff --git a/deploy.sh b/deploy.sh
new file mode 100755 (executable)
index 0000000..ac4c8a6
--- /dev/null
+++ b/deploy.sh
@@ -0,0 +1,97 @@
+#!/usr/bin/bash
+# build the image and push to container registry
+
+# helpers
+
+section="" ## Formatted as <verb> <noun>
+function echoSection() {
+  if [ -z "$1" ] ; then
+    echo""
+    echo "--- $0: $section ---"
+  else
+    echo "--- $0: $section $1 ---"
+  fi
+}
+
+## intro
+section="Printing Info"
+echoSection ""
+echo "Deploying yampl, a toml to html site generator."
+echo "commit id: $(git rev-list --max-count=1 HEAD)"
+echo "go version: $(go version)"
+echo "podman version: $(podman --version)"
+echo "buildah version: $(buildah --version)"
+
+echoSection "end"
+
+
+## check codebase
+section="Checking Codebase"
+echoSection ""
+
+set -x
+fmtout=$(go run cmd/gofmt -e -l -d .)
+set +x
+# TODO go fix 
+# TODO go vet
+# TODO golangcli lint
+if [ -n "$fmtout" ] ; then
+  echo "$fmtout"
+  echoSection "failure"
+  exit -1
+fi
+
+echoSection "success"
+
+## build Containerfile
+section="Building Containerfile"
+echoSection ""
+
+image="localhost/yampl"
+
+buildah build -f Containerfile -t $image
+if [ $? -eq 0 ] ; then
+  echoSection "success"
+else
+  echoSection "failure"
+  exit -2
+fi
+
+## push container to the registry
+section="push image"
+echoSection ""
+
+if [ -z "$CONTAINER_REGISTRY_USERNAME$CONTAINER_REGISTRY_PASSWORD"] ; then
+  echoSection "skip"
+else
+  gitbranch="git rev-pars --abrev-ref HEAD"
+
+  newimage="containers.openfl.eu/local/yampl:$gitbranch"
+  podman tag $image $newimage
+  image=$newimage
+  podman login --username $CONTAINER_REGISTRY_USERNAME --password $CONTAINER_REGISTRY_PASSWORD containers.openfl.eu
+  podman push "containers.openfl.eu/local/yampl:$gitbranch"
+  if [ $? -ne 0 ] ; then
+    echoSection "failure"
+    exit -3
+  fi
+fi
+
+echoSection "success"
+
+## update the content of the volumes
+section="update data"
+echoSection ""
+echoSection "success"
+
+## restart the service
+section="restart container"
+echoSection ""
+podman compose pull && \
+podman compose down && \
+podman compose up -d
+if [ $? -ne 0 ] ; then
+  echoSection "failure"
+  exit -4
+fi
+echoSection "success"
diff --git a/main.go b/main.go
index d9717c4d988ffec527872d04af3c60346093a651..35be7b58b5a16bf00494c4ab963d016a0374c2e3 100644 (file)
--- a/main.go
+++ b/main.go
@@ -45,7 +45,7 @@ func listRespond(w http.ResponseWriter, r *http.Request) {
                log.Println(err)
                return
        }
-       
+
        for i, it := range data.Items {
                it["_index"] = i
                it["_url"] = fmt.Sprintf("/items/%d", i)