From dce4bf4e362e68d9b26814abb5e7509dfd185e79 Mon Sep 17 00:00:00 2001 From: kjuulh Date: Sat, 1 Jul 2023 23:40:16 +0200 Subject: [PATCH] feat: with initial rust service Signed-off-by: kjuulh --- cuddle.yaml | 16 ------------- scripts/build_release.sh | 22 ----------------- scripts/deploy_release.sh | 10 -------- scripts/local_down.sh | 7 ++++++ scripts/local_up.sh | 7 ++++++ scripts/migrate.sh | 6 +++++ scripts/new_migration.sh | 5 ++++ scripts/push_release.sh | 16 ------------- scripts/render_templates.sh | 11 --------- scripts/run.sh | 5 ++++ scripts/run_release.sh | 20 ---------------- scripts/setup_ssh.sh | 24 ------------------- scripts/sqlx:prepare.sh | 7 ++++++ scripts/start_deployment.sh | 17 ------------- templates/.env.example.tmpl | 4 ++++ templates/build_release.Dockerfile | 11 --------- .../build_release.Dockerfile.dockerignore | 2 -- .../docker-compose.deploy_release.yml.tmpl | 17 ------------- .../docker-compose.local_up.dockerignore | 7 ++++++ templates/docker-compose.local_up.yml.tmpl | 17 +++++++++++++ templates/init-user-db.sh | 8 +++++++ templates/local_up.Dockerfile | 3 +++ 22 files changed, 76 insertions(+), 166 deletions(-) delete mode 100755 scripts/build_release.sh delete mode 100755 scripts/deploy_release.sh create mode 100755 scripts/local_down.sh create mode 100755 scripts/local_up.sh create mode 100755 scripts/migrate.sh create mode 100755 scripts/new_migration.sh delete mode 100755 scripts/push_release.sh delete mode 100755 scripts/render_templates.sh create mode 100755 scripts/run.sh delete mode 100755 scripts/run_release.sh delete mode 100755 scripts/setup_ssh.sh create mode 100755 scripts/sqlx:prepare.sh delete mode 100755 scripts/start_deployment.sh create mode 100644 templates/.env.example.tmpl delete mode 100644 templates/build_release.Dockerfile delete mode 100644 templates/build_release.Dockerfile.dockerignore delete mode 100644 templates/docker-compose.deploy_release.yml.tmpl create mode 100644 templates/docker-compose.local_up.dockerignore create mode 100644 templates/docker-compose.local_up.yml.tmpl create mode 100644 templates/init-user-db.sh create mode 100644 templates/local_up.Dockerfile diff --git a/cuddle.yaml b/cuddle.yaml index 7bfac21..d652eee 100644 --- a/cuddle.yaml +++ b/cuddle.yaml @@ -4,19 +4,3 @@ base: "git@git.front.kjuulh.io:kjuulh/cuddle-base.git" vars: registry: "kasperhermansen" port: "3000:3000" - -scripts: - build_release: - type: shell - run_release: - type: shell - start_deployment: - type: shell - render_templates: - type: shell - deploy_release: - type: shell - setup_ssh: - type: shell - push_release: - type: shell diff --git a/scripts/build_release.sh b/scripts/build_release.sh deleted file mode 100755 index 24ba872..0000000 --- a/scripts/build_release.sh +++ /dev/null @@ -1,22 +0,0 @@ -#!/bin/bash - -echo "building docker image" - -base_tag="$REGISTRY/$SERVICE" -tag="$base_tag:${COMMIT_SHA:0:10}" -latest_tag="$base_tag:latest" - -if [[ -n $DEBUG ]] -then - echo "debug:" - echo " REGISTRY: $REGISTRY" - echo " SERVICE: $SERVICE" - echo " COMMIT_SHA: $COMMIT_SHA" - echo " TMP: $TMP" -fi - -docker login -u $DOCKER_USERNAME -p $DOCKER_PASSWORD -docker pull "$latest_tag" - -DOCKER_BUILDKIT=1 docker build --cache-from "$latest_tag" -t "$tag" -f "$TMP/build_release.Dockerfile" . -docker tag "$tag" "$latest_tag" diff --git a/scripts/deploy_release.sh b/scripts/deploy_release.sh deleted file mode 100755 index 250eac4..0000000 --- a/scripts/deploy_release.sh +++ /dev/null @@ -1,10 +0,0 @@ -#!/bin/bash - -set -e - -echo "deploying image" -deploymentrepo="$TMP/deployments" - -cd $deploymentrepo - -git add . && git commit -m "Added release $SERVICE: ${COMMIT_SHA:0:10}" && git pull && git push diff --git a/scripts/local_down.sh b/scripts/local_down.sh new file mode 100755 index 0000000..cbb90a3 --- /dev/null +++ b/scripts/local_down.sh @@ -0,0 +1,7 @@ +#!/bin/bash + +set -e + +cuddle render_template --template-file $TMP/docker-compose.local_up.yml.tmpl --dest $TMP/docker-compose.local_up.yml + +docker compose -f $TMP/docker-compose.local_up.yml down -v diff --git a/scripts/local_up.sh b/scripts/local_up.sh new file mode 100755 index 0000000..ab4369e --- /dev/null +++ b/scripts/local_up.sh @@ -0,0 +1,7 @@ +#!/bin/bash + +set -e + +cuddle render_template --template-file $TMP/docker-compose.local_up.yml.tmpl --dest $TMP/docker-compose.local_up.yml + +docker compose -f $TMP/docker-compose.local_up.yml up -d --remove-orphans --build diff --git a/scripts/migrate.sh b/scripts/migrate.sh new file mode 100755 index 0000000..b976519 --- /dev/null +++ b/scripts/migrate.sh @@ -0,0 +1,6 @@ +#!/bin/bash + +export $(cat .env | xargs) + +cargo sqlx migrate run --source "crates/$service/migrations" --database-url=$DATABASE_URL + diff --git a/scripts/new_migration.sh b/scripts/new_migration.sh new file mode 100755 index 0000000..c6100a1 --- /dev/null +++ b/scripts/new_migration.sh @@ -0,0 +1,5 @@ +#!/bin/bash + +export $(cat .env | xargs) + +cargo sqlx migrate add "--source crates/$service/migrations" $name diff --git a/scripts/push_release.sh b/scripts/push_release.sh deleted file mode 100755 index 32d81d0..0000000 --- a/scripts/push_release.sh +++ /dev/null @@ -1,16 +0,0 @@ -#!/bin/bash - -set -e - -base_tag="$REGISTRY/$SERVICE" -tag="$base_tag:${COMMIT_SHA:0:10}" -latest_tag="$base_tag:latest" - -export DOCKER_BUILDKIT=1 - -echo "docker: logging in" -docker login -u $DOCKER_USERNAME -p $DOCKER_PASSWORD - -echo "docker: pushing image $tag" -docker push --all-tags "$base_tag" - diff --git a/scripts/render_templates.sh b/scripts/render_templates.sh deleted file mode 100755 index 31317d1..0000000 --- a/scripts/render_templates.sh +++ /dev/null @@ -1,11 +0,0 @@ -#!/bin/bash - -set -e - -tag="$REGISTRY/$SERVICE:${COMMIT_SHA:0:10}" -deploymentrepo="$TMP/deployments" - -CUDDLE_FETCH_POLICY=never cuddle_cli render_template \ - --template-file "$TMP/docker-compose.deploy_release.yml.tmpl" \ - --dest "$deploymentrepo/$SERVICE/docker-compose.yml" \ - --extra-var "image=$tag" diff --git a/scripts/run.sh b/scripts/run.sh new file mode 100755 index 0000000..4fe30c0 --- /dev/null +++ b/scripts/run.sh @@ -0,0 +1,5 @@ +#!/bin/bash + +set -e + +(cd crates/$service; cargo watch -x run) diff --git a/scripts/run_release.sh b/scripts/run_release.sh deleted file mode 100755 index d22c63d..0000000 --- a/scripts/run_release.sh +++ /dev/null @@ -1,20 +0,0 @@ -#!/bin/bash - -set -e - -echo "prebuiliding docker image" - -cuddle_cli x build_release - -echo "running docker image" - -tag="$REGISTRY/$SERVICE:${COMMIT_SHA:0:10}" - -container_id=$(docker run -d "$tag") - -sleep 5s - -docker logs "$container_id" - -echo "removing image" -docker stop "$container_id" > /dev/null && docker rm "$container_id" > /dev/null diff --git a/scripts/setup_ssh.sh b/scripts/setup_ssh.sh deleted file mode 100755 index ae86915..0000000 --- a/scripts/setup_ssh.sh +++ /dev/null @@ -1,24 +0,0 @@ -#!/bin/sh - -set -e - -if [ ! -d ~/.ssh ]; then - mkdir -p ~/.ssh - chmod 700 ~/.ssh -fi - -if [ -n "$SSH_KEY" ]; then - SSH_KEY_ID="$HOME/.ssh/id_ed25519" - echo $SSH_KEY | base64 -d > $SSH_KEY_ID - - chmod 600 $SSH_KEY_ID - - cat >$HOME/.ssh/config <