Add cuddle
This commit is contained in:
59
scripts/build_release.sh
Executable file
59
scripts/build_release.sh
Executable 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
10
scripts/deploy_release.sh
Executable 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
|
@@ -1,63 +0,0 @@
|
||||
# Step 1. Rebuild the source code only when needed
|
||||
FROM node:18-alpine AS builder
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
# Install dependencies based on the preferred package manager
|
||||
COPY package.json yarn.lock* package-lock.json* pnpm-lock.yaml* ./
|
||||
# Omit --production flag for TypeScript devDependencies
|
||||
RUN \
|
||||
if [ -f yarn.lock ]; then yarn --frozen-lockfile; \
|
||||
elif [ -f package-lock.json ]; then npm ci; \
|
||||
elif [ -f pnpm-lock.yaml ]; then yarn global add pnpm && pnpm i; \
|
||||
else echo "Lockfile not found." && exit 1; \
|
||||
fi
|
||||
|
||||
|
||||
COPY src ./src
|
||||
COPY public ./public
|
||||
COPY posts ./posts
|
||||
COPY next.config.js .
|
||||
COPY tsconfig.json .
|
||||
|
||||
# Environment variables must be present at build time
|
||||
# https://github.com/vercel/next.js/discussions/14030
|
||||
ARG ENV_VARIABLE
|
||||
ENV ENV_VARIABLE=${ENV_VARIABLE}
|
||||
ARG NEXT_PUBLIC_ENV_VARIABLE
|
||||
ENV NEXT_PUBLIC_ENV_VARIABLE=${NEXT_PUBLIC_ENV_VARIABLE}
|
||||
|
||||
# Uncomment the following line to disable telemetry at build time
|
||||
# ENV NEXT_TELEMETRY_DISABLED 1
|
||||
|
||||
RUN yarn build
|
||||
|
||||
# Step 2. Production image, copy all the files and run next
|
||||
FROM node:18-alpine AS runner
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
# Don't run production as root
|
||||
RUN addgroup --system --gid 1001 nodejs
|
||||
RUN adduser --system --uid 1001 nextjs
|
||||
USER nextjs
|
||||
|
||||
COPY --from=builder /app/public ./public
|
||||
|
||||
# Automatically leverage output traces to reduce image size
|
||||
# https://nextjs.org/docs/advanced-features/output-file-tracing
|
||||
COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
|
||||
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static
|
||||
COPY --from=builder --chown=nextjs:nodejs /app/posts ./posts
|
||||
|
||||
# Environment variables must be redefined at run time
|
||||
ARG ENV_VARIABLE
|
||||
ENV ENV_VARIABLE=${ENV_VARIABLE}
|
||||
ARG NEXT_PUBLIC_ENV_VARIABLE
|
||||
ENV NEXT_PUBLIC_ENV_VARIABLE=${NEXT_PUBLIC_ENV_VARIABLE}
|
||||
|
||||
# Uncomment the following line to disable telemetry at run time
|
||||
# ENV NEXT_TELEMETRY_DISABLED 1
|
||||
|
||||
CMD node server.js
|
||||
|
5
scripts/download.sh
Executable file
5
scripts/download.sh
Executable file
@@ -0,0 +1,5 @@
|
||||
#!/bin/bash
|
||||
|
||||
set -e
|
||||
|
||||
pnpm i
|
10
scripts/generate_graphql.sh
Executable file
10
scripts/generate_graphql.sh
Executable 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
40
scripts/push_release.sh
Executable 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
11
scripts/render_templates.sh
Executable 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
24
scripts/setup_ssh.sh
Executable 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
17
scripts/start_deployment.sh
Executable 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"
|
||||
|
Reference in New Issue
Block a user