added scripts
Some checks failed
continuous-integration/drone/push Build is failing

This commit is contained in:
Kasper Juul Hermansen 2022-08-26 08:20:37 +02:00
parent 3791c5df6b
commit 9cca1cfacc
Signed by: kjuulh
GPG Key ID: 57B6E1465221F912
8 changed files with 176 additions and 0 deletions

59
scripts/build_release.sh Executable file
View File

@ -0,0 +1,59 @@
#!/bin/bash
set -e
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
echo "docker: logging in"
docker login -u $DOCKER_USERNAME -p $DOCKER_PASSWORD
export DOCKER_BUILDKIT=1
function pull_target {
target=$1
echo "pulling $target"
latest_target_tag="$base_tag-$target:latest"
docker pull $latest_target_tag
}
function build_target {
target=$1
echo "building $target"
latest_target_tag="$base_tag-$target:latest"
docker build \
--target "$target" \
--tag "$latest_target_tag" \
--build-arg BUILDKIT_INLINE_CACHE=1 \
--cache-from $latest_target_tag \
--file "$TMP/build_release.Dockerfile" .
}
pull_target "deps" &
pull_target "builder" &
wait
build_target "deps"
build_target "builder"
docker build \
-t "$tag" \
--cache-from "$base_tag-deps:latest" \
--cache-from "$base_tag-builder:latest" \
--build-arg BUILDKIT_INLINE_CACHE=1 \
--cache-from $latest_tag \
-f "$TMP/build_release.Dockerfile" .
docker tag "$tag" "$latest_tag"

10
scripts/deploy_release.sh Executable file
View File

@ -0,0 +1,10 @@
#!/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

5
scripts/download.sh Executable file
View File

@ -0,0 +1,5 @@
#!/bin/bash
set -e
pnpm i

10
scripts/generate_graphql.sh Executable file
View File

@ -0,0 +1,10 @@
#!/bin/bash
set -e
cuddle_cli x download
pnpm run generate:graphql
pnpm run format:graphql
git diff src/lib/graphql/generated.ts

40
scripts/push_release.sh Executable file
View File

@ -0,0 +1,40 @@
#!/bin/bash
set -e
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
echo "docker: logging in"
docker login -u $DOCKER_USERNAME -p $DOCKER_PASSWORD
export DOCKER_BUILDKIT=1
function push_target {
target=$1
echo "pushing $target"
latest_target_tag="$base_tag-$target:latest"
docker push "$latest_target_tag"
}
function push_main_target {
echo "docker: pushing image $tag"
docker push "$tag"
docker push "$latest_tag"
}
push_target "deps" &
push_target "builder" &
push_main_target &
wait

11
scripts/render_templates.sh Executable file
View File

@ -0,0 +1,11 @@
#!/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"

24
scripts/setup_ssh.sh Executable file
View File

@ -0,0 +1,24 @@
#!/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

17
scripts/start_deployment.sh Executable file
View File

@ -0,0 +1,17 @@
#!/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"