feat: with initial rust service
Signed-off-by: kjuulh <contact@kjuulh.io>
This commit is contained in:
parent
7310e6a15f
commit
dce4bf4e36
16
cuddle.yaml
16
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
|
||||
|
@ -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"
|
@ -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
7
scripts/local_down.sh
Executable 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
7
scripts/local_up.sh
Executable 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
6
scripts/migrate.sh
Executable 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
5
scripts/new_migration.sh
Executable file
@ -0,0 +1,5 @@
|
||||
#!/bin/bash
|
||||
|
||||
export $(cat .env | xargs)
|
||||
|
||||
cargo sqlx migrate add "--source crates/$service/migrations" $name
|
@ -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"
|
||||
|
@ -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
5
scripts/run.sh
Executable file
@ -0,0 +1,5 @@
|
||||
#!/bin/bash
|
||||
|
||||
set -e
|
||||
|
||||
(cd crates/$service; cargo watch -x run)
|
@ -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
|
@ -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
7
scripts/sqlx:prepare.sh
Executable file
@ -0,0 +1,7 @@
|
||||
#!/bin/bash
|
||||
|
||||
export $(cat .env | xargs)
|
||||
|
||||
cd crates/$service || return
|
||||
|
||||
cargo sqlx prepare -- --all-targets --all-features
|
@ -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"
|
||||
|
4
templates/.env.example.tmpl
Normal file
4
templates/.env.example.tmpl
Normal file
@ -0,0 +1,4 @@
|
||||
POSTGRES_DB=como
|
||||
POSTGRES_USER=como
|
||||
POSTGRES_PASSWORD=somenotverysecurepassword
|
||||
DATABASE_URL="postgres://como:somenotverysecurepassword@localhost:5432/como"
|
@ -1,11 +0,0 @@
|
||||
FROM rust:1.69.0-slim-buster
|
||||
|
||||
RUN apt-get update && apt-get upgrade -y
|
||||
RUN apt-get install libssl-dev
|
||||
RUN apt-get install -y -q build-essential curl
|
||||
|
||||
COPY . .
|
||||
|
||||
RUN cargo build
|
||||
|
||||
CMD [ "cargo", "run" ]
|
@ -1,2 +0,0 @@
|
||||
target/
|
||||
.cuddle/
|
@ -1,17 +0,0 @@
|
||||
version: '3.7'
|
||||
|
||||
services:
|
||||
{{ service }}:
|
||||
image: {{ image }}
|
||||
ports:
|
||||
- {{ port }}
|
||||
env_file: ".env"
|
||||
restart: always
|
||||
depends_on:
|
||||
- db
|
||||
db:
|
||||
image: postgres:13.5
|
||||
restart: always
|
||||
env_file: ".env"
|
||||
volumes:
|
||||
- ./data/postgres:/var/lib/postgresql/data
|
7
templates/docker-compose.local_up.dockerignore
Normal file
7
templates/docker-compose.local_up.dockerignore
Normal file
@ -0,0 +1,7 @@
|
||||
target/
|
||||
.git/
|
||||
.cuddle/
|
||||
scripts/
|
||||
cuddle.yaml
|
||||
local.sh
|
||||
README.md
|
17
templates/docker-compose.local_up.yml.tmpl
Normal file
17
templates/docker-compose.local_up.yml.tmpl
Normal file
@ -0,0 +1,17 @@
|
||||
version: '3.7'
|
||||
|
||||
services:
|
||||
db:
|
||||
build:
|
||||
context: .
|
||||
dockerfile: local_up.Dockerfile
|
||||
restart: always
|
||||
environment:
|
||||
- POSTGRES_PASSWORD=somenotverysecurepassword
|
||||
ports:
|
||||
- 5432:5432
|
||||
volumes:
|
||||
- pgdata:/var/lib/postgresql/data
|
||||
|
||||
volumes:
|
||||
pgdata:
|
8
templates/init-user-db.sh
Normal file
8
templates/init-user-db.sh
Normal file
@ -0,0 +1,8 @@
|
||||
#!bin/bash
|
||||
set -e
|
||||
|
||||
psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" <<-EOSQL
|
||||
CREATE USER como WITH PASSWORD 'somenotverysecurepassword';
|
||||
CREATE DATABASE cuddle;
|
||||
GRANT ALL PRIVILEGES ON DATABASE cuddle TO cuddle;
|
||||
EOSQL
|
3
templates/local_up.Dockerfile
Normal file
3
templates/local_up.Dockerfile
Normal file
@ -0,0 +1,3 @@
|
||||
FROM postgres:14-alpine
|
||||
|
||||
COPY *.sh /docker-entrypoint-initdb.d/
|
Loading…
Reference in New Issue
Block a user