feat: with initial rust service

Signed-off-by: kjuulh <contact@kjuulh.io>
This commit is contained in:
2023-07-01 23:40:16 +02:00
parent 7310e6a15f
commit dce4bf4e36
22 changed files with 76 additions and 166 deletions

View File

@@ -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"

View File

@@ -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

7
scripts/local_down.sh Executable file
View File

@@ -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

7
scripts/local_up.sh Executable file
View File

@@ -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

6
scripts/migrate.sh Executable file
View File

@@ -0,0 +1,6 @@
#!/bin/bash
export $(cat .env | xargs)
cargo sqlx migrate run --source "crates/$service/migrations" --database-url=$DATABASE_URL

5
scripts/new_migration.sh Executable file
View File

@@ -0,0 +1,5 @@
#!/bin/bash
export $(cat .env | xargs)
cargo sqlx migrate add "--source crates/$service/migrations" $name

View File

@@ -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"

View File

@@ -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"

5
scripts/run.sh Executable file
View File

@@ -0,0 +1,5 @@
#!/bin/bash
set -e
(cd crates/$service; cargo watch -x run)

View File

@@ -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

View File

@@ -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 <<EOL
Host git.front.kjuulh.io
IdentityFile ${SSH_KEY_ID}
IdentitiesOnly yes
UserKnownHostsFile=/dev/null
StrictHostKeyChecking no
EOL
fi

7
scripts/sqlx:prepare.sh Executable file
View File

@@ -0,0 +1,7 @@
#!/bin/bash
export $(cat .env | xargs)
cd crates/$service || return
cargo sqlx prepare -- --all-targets --all-features

View File

@@ -1,17 +0,0 @@
#!/bin/bash
set -e
echo "Starting deployment"
deploymentrepo="$TMP/deployments"
[ -d $deploymentrepo ] && rm -rf $deploymentrepo
git clone "$DEPLOYMENTS" $deploymentrepo
[ ! -d $deploymentrepo ] && echo "deployments could not be cloned aborting" && exit 1
echo "$deploymentrepo"
mkdir -p "$deploymentrepo/$SERVICE"