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

This commit is contained in:
Kasper Juul Hermansen 2022-08-20 23:39:36 +02:00
parent 83b62a4953
commit 295acff548
Signed by: kjuulh
GPG Key ID: 0F95C140730F2F23
13 changed files with 297 additions and 0 deletions

View File

@ -0,0 +1,60 @@
# Install dependencies only when needed
FROM node:16-alpine AS deps
# Check https://github.com/nodejs/docker-node/tree/b4117f9333da4138b03a546ec926ef50a31506c3#nodealpine to understand why libc6-compat might be needed.
RUN apk add --no-cache libc6-compat
WORKDIR /app
# Install dependencies based on the preferred package manager
COPY package.json yarn.lock* package-lock.json* pnpm-lock.yaml* ./
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
# Rebuild the source code only when needed
FROM node:16-alpine AS builder
WORKDIR /app
COPY --from=deps /app/node_modules ./node_modules
COPY . .
# Next.js collects completely anonymous telemetry data about general usage.
# Learn more here: https://nextjs.org/telemetry
# Uncomment the following line in case you want to disable telemetry during the build.
# ENV NEXT_TELEMETRY_DISABLED 1
RUN yarn build
# If using npm comment out above and use below instead
# RUN npm run build
# Production image, copy all the files and run next
FROM node:16-alpine AS runner
WORKDIR /app
ENV NODE_ENV production
# Uncomment the following line in case you want to disable telemetry during runtime.
# ENV NEXT_TELEMETRY_DISABLED 1
RUN addgroup --system --gid 1001 nodejs
RUN adduser --system --uid 1001 nextjs
# You only need to copy next.config.js if you are NOT using the default configuration
# COPY --from=builder /app/next.config.js ./
COPY --from=builder /app/public ./public
COPY --from=builder /app/package.json ./package.json
# 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
USER nextjs
EXPOSE 3000
ENV PORT 3000
CMD ["node", "server.js"]

View File

@ -0,0 +1,4 @@
.next/
.git/
.cuddle/
node_modules/

68
.drone.yml Normal file
View File

@ -0,0 +1,68 @@
kind: pipeline
name: default
type: docker
steps:
- name: load_secret
image: debian:buster-slim
volumes:
- name: ssh
path: /root/.ssh/
environment:
SSH_KEY:
from_secret: gitea_id_ed25519
commands:
- mkdir -p $HOME/.ssh/
- echo "$SSH_KEY" | base64 -d > $HOME/.ssh/id_ed25519
- name: build
image: kasperhermansen/cuddle:latest
pull: always
volumes:
- name: ssh
path: /root/.ssh/
- name: dockersock
path: /var/run
commands:
- apk add bash git
- cuddle_cli x setup_ssh
- cuddle_cli x render_templates
- cuddle_cli x start_deployment
- cuddle_cli x build_release
- cuddle_cli x deploy_release
environment:
DOCKER_BUILDKIT: 1
DOCKER_USERNAME:
from_secret: docker_username
DOCKER_PASSWORD:
from_secret: docker_password
SSH_KEY:
from_secret: gitea_id_ed25519
depends_on:
- "load_secret"
- name: send telegram notification
image: appleboy/drone-telegram
settings:
token:
from_secret: telegram_token
to: 2129601481
format: markdown
depends_on:
- build
when:
status: [failure, success]
services:
- name: docker
image: docker:dind
privileged: true
volumes:
- name: dockersock
path: /var/run
volumes:
- name: ssh
temp: {}
- name: dockersock
temp: {}

View File

@ -4,9 +4,21 @@ base: false
vars:
service: "cibus-frontend"
registry: kasperhermansen
port: 3001:3001
scripts:
generate_graphql:
type: shell
download:
type: shell
build_release:
type: shell
setup_ssh:
type: shell
deploy_release:
type: shell
start_deployment:
type: shell
render_templates:
type: shell

View File

@ -1,4 +1,5 @@
/** @type {import('next').NextConfig} */
module.exports = {
reactStrictMode: true,
output: 'standalone'
}

17
scripts/build_release.sh Executable file
View File

@ -0,0 +1,17 @@
#!/bin/bash
set -e
tag="$REGISTRY/$SERVICE:${COMMIT_SHA:0:10}"
if [[ -n $DEBUG ]]
then
echo "debug:"
echo " REGISTRY: $REGISTRY"
echo " SERVICE: $SERVICE"
echo " COMMIT_SHA: $COMMIT_SHA"
echo " TMP: $TMP"
fi
DOCKER_BUILDKIT=1 docker build -t "$tag" -f "$TMP/build_release.Dockerfile" .

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

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"

View File

@ -0,0 +1,60 @@
# Install dependencies only when needed
FROM node:16-alpine AS deps
# Check https://github.com/nodejs/docker-node/tree/b4117f9333da4138b03a546ec926ef50a31506c3#nodealpine to understand why libc6-compat might be needed.
RUN apk add --no-cache libc6-compat
WORKDIR /app
# Install dependencies based on the preferred package manager
COPY package.json yarn.lock* package-lock.json* pnpm-lock.yaml* ./
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
# Rebuild the source code only when needed
FROM node:16-alpine AS builder
WORKDIR /app
COPY --from=deps /app/node_modules ./node_modules
COPY . .
# Next.js collects completely anonymous telemetry data about general usage.
# Learn more here: https://nextjs.org/telemetry
# Uncomment the following line in case you want to disable telemetry during the build.
# ENV NEXT_TELEMETRY_DISABLED 1
RUN yarn build
# If using npm comment out above and use below instead
# RUN npm run build
# Production image, copy all the files and run next
FROM node:16-alpine AS runner
WORKDIR /app
ENV NODE_ENV production
# Uncomment the following line in case you want to disable telemetry during runtime.
# ENV NEXT_TELEMETRY_DISABLED 1
RUN addgroup --system --gid 1001 nodejs
RUN adduser --system --uid 1001 nextjs
# You only need to copy next.config.js if you are NOT using the default configuration
# COPY --from=builder /app/next.config.js ./
COPY --from=builder /app/public ./public
COPY --from=builder /app/package.json ./package.json
# 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
USER nextjs
EXPOSE 3000
ENV PORT 3000
CMD ["node", "server.js"]

View File

@ -0,0 +1,4 @@
.next/
.git/
.cuddle/
node_modules/

View File

@ -0,0 +1,9 @@
version: '3.7'
services:
{{ service }}:
image: {{ image }}
ports:
- {{ port }}
env_file: ".env"
restart: always