From e6475bca37d910823399e53bffc9dc7f761d3e53 Mon Sep 17 00:00:00 2001 From: Daniel Kluge Date: Tue, 14 Dec 2021 23:00:41 +0100 Subject: [PATCH] Add CI/CD --- .drone.yml | 84 +++++++++++++++++++++++++++++++++++++++ Dockerfile | 39 ++++++++++++++++++ docker-compose.dev.yml | 25 ++++++++++++ docker-compose.stable.yml | 25 ++++++++++++ 4 files changed, 173 insertions(+) create mode 100644 .drone.yml create mode 100644 Dockerfile create mode 100644 docker-compose.dev.yml create mode 100644 docker-compose.stable.yml diff --git a/.drone.yml b/.drone.yml new file mode 100644 index 0000000..f94ec11 --- /dev/null +++ b/.drone.yml @@ -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 \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..f420415 --- /dev/null +++ b/Dockerfile @@ -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"] \ No newline at end of file diff --git a/docker-compose.dev.yml b/docker-compose.dev.yml new file mode 100644 index 0000000..68c95ad --- /dev/null +++ b/docker-compose.dev.yml @@ -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 \ No newline at end of file diff --git a/docker-compose.stable.yml b/docker-compose.stable.yml new file mode 100644 index 0000000..9c39f28 --- /dev/null +++ b/docker-compose.stable.yml @@ -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 \ No newline at end of file