Add CI/CD

This commit is contained in:
Daniel Kluge 2021-12-14 23:00:41 +01:00
parent 894364ff90
commit e6475bca37
4 changed files with 173 additions and 0 deletions

84
.drone.yml Normal file
View File

@ -0,0 +1,84 @@
kind: pipeline
type: docker
name: build
trigger:
event:
- push
steps:
- name: tag-commit-hash
image: alpine
commands:
- echo '${DRONE_COMMIT:0:8}' > .tags
- name: tag-dev
image: alpine
when:
branch:
- dev
commands:
- sed -i '$s/$/,dev/' .tags
- name: tag-latest
image: alpine
when:
branch:
- senpai
commands:
- sed -i '$s/$/,latest/' .tags
- name: build-image
image: plugins/docker
settings:
repo: c0ntroller/c0ntroller.de
username:
from_secret: docker_user
password:
from_secret: docker_token
---
kind: pipeline
type: ssh
name: deploy
depends_on:
- build
trigger:
branch:
- main
- dev
event:
- push
server:
host:
from_secret: ssh_host
user:
from_secret: ssh_user
ssh_key:
from_secret: ssh_key
steps:
- name: deploy-dev
when:
branch:
- dev
environment:
DOCKER_USER:
from_secret: docker_user
DOCKER_PASS:
from_secret: docker_token
IMAGE: c0ntroller/c0ntroller.de:dev
commands:
- docker login -u $${DOCKER_USER} -p $${DOCKER_PASS}
- docker-compose -p website-dev -f docker-compose.dev.yml rm -s -v -f
- docker rmi $${IMAGE}
- docker pull $${IMAGE}
- docker-compose -p website-dev -f docker-compose.dev.yml up --no-build -d
- name: deploy-stable
when:
branch:
- main
environment:
DOCKER_USER:
from_secret: docker_user
DOCKER_PASS:
from_secret: docker_token
commands:
- docker login -u $${DOCKER_USER} -p $${DOCKER_PASS}
- docker-compose -p website -f docker-compose.stable.yml rm -s -v -f
- docker rmi $${IMAGE}
- docker pull $${IMAGE}
- docker-compose -p website -f docker-compose.stable.yml up --no-build -d

39
Dockerfile Normal file
View File

@ -0,0 +1,39 @@
# From https://nextjs.org/docs/deployment
# Rebuild the source code only when needed
FROM node:alpine AS builder
RUN apk add --no-cache libc6-compat
WORKDIR /app
COPY package.json package-lock.json ./
RUN npm ci
COPY . .
RUN npm run build
# Production image, copy all the files and run next
FROM node:alpine AS runner
WORKDIR /app
ENV NODE_ENV production
RUN addgroup -g 1001 -S nodejs
RUN adduser -S nextjs -u 1001
# 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 --chown=nextjs:nodejs /app/.next ./.next
COPY --from=builder /app/node_modules ./node_modules
COPY --from=builder /app/package.json ./package.json
USER nextjs
EXPOSE 3000
ENV PORT 3000
# 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.
ENV NEXT_TELEMETRY_DISABLED 1
CMD ["node_modules/.bin/next", "start"]

25
docker-compose.dev.yml Normal file
View File

@ -0,0 +1,25 @@
version: '3'
services:
server:
image: c0ntroller/c0ntroller.de:dev
restart: always
networks:
- traefik
labels:
- "traefik.enable=true"
- "traefik.docker.network=traefik"
- "traefik.http.routers.website-dev.entrypoints=web"
- "traefik.http.routers.website-dev.rule=Host(`dev.c0ntroller.de`)"
- "traefik.http.routers.website-dev.middlewares=http-to-https@file"
- "traefik.http.routers.website-dev-secure.entrypoints=websecure"
- "traefik.http.routers.website-dev-secure.rule=Host(`dev.c0ntroller.de`)"
- "traefik.http.routers.website-dev-secure.middlewares=secHeaders@file"
- "traefik.http.routers.website-dev-secure.tls=true"
- "traefik.http.routers.website-dev-secure.tls.certresolver=le"
- "traefik.http.routers.website-dev-secure.service=website-dev"
- "traefik.http.services.website-dev.loadbalancer.server.port=3000"
networks:
traefik:
external: true

25
docker-compose.stable.yml Normal file
View File

@ -0,0 +1,25 @@
version: '3'
services:
server:
image: c0ntroller/c0ntroller.de:stable
restart: always
networks:
- traefik
labels:
- "traefik.enable=true"
- "traefik.docker.network=traefik"
- "traefik.http.routers.website-stable.entrypoints=web"
- "traefik.http.routers.website-stable.rule=Host(`c0ntroller.de`)"
- "traefik.http.routers.website-stable.middlewares=http-to-https@file"
- "traefik.http.routers.website-stable-secure.entrypoints=websecure"
- "traefik.http.routers.website-stable-secure.rule=Host(`c0ntroller.de`)"
- "traefik.http.routers.website-stable-secure.middlewares=secHeaders@file"
- "traefik.http.routers.website-stable-secure.tls=true"
- "traefik.http.routers.website-stable-secure.tls.certresolver=le"
- "traefik.http.routers.website-stable-secure.service=website-stable"
- "traefik.http.services.website-stable.loadbalancer.server.port=3000"
networks:
traefik:
external: true