Skip to content

Instantly share code, notes, and snippets.

@evzpav
Last active March 23, 2023 18:33
Show Gist options
  • Save evzpav/ededee4327055d99ea6f886679829b78 to your computer and use it in GitHub Desktop.
Save evzpav/ededee4327055d99ea6f886679829b78 to your computer and use it in GitHub Desktop.
Gitlab CI config for Dokku project
stages:
- deploy
variables:
APP_NAME: app-name
GIT_DEPTH: 0
deploy:
stage: deploy
image: ilyasemenov/gitlab-ci-git-push
environment:
name: production
only:
- main
script:
- git-push ssh://dokku@$VM_IP:22/$APP_NAME
# ---- Base Node ----
FROM node:12-stretch-slim AS base
ENV NODE_ENV=development
RUN mkdir /app && chown -R node:node /app
RUN mkdir /app/vue-client && chown -R node:node /app/vue-client
WORKDIR /app
USER node
RUN npm set progress=false && npm config set depth 0
# ---- Audit ----
FROM base AS audit
COPY --chown=node:node package*.json ./
RUN npm audit
# ---- Dependencies ----
FROM base AS server-dependencies
WORKDIR /app
COPY --chown=node:node package*.json ./
RUN npm ci --production && npm cache clean --force
# #---- Test ----
FROM server-dependencies AS test
RUN npm ci --development
COPY --chown=node:node ./server ./server
RUN npm test
# ---- Frontend Dependencies ----
FROM base AS front-dependencies
WORKDIR /app/vue-client
COPY --chown=node:node ./vue-client/package*.json ./
RUN npm ci && npm cache clean --force
# ---- Front ----
FROM front-dependencies AS front
WORKDIR /app/vue-client
COPY --chown=node:node ./vue-client ./
RUN npm run build
# ---- Release ----
FROM server-dependencies AS release
WORKDIR /app
COPY --chown=node:node --from=front /app/vue-client/build ./vue-client/build
COPY --chown=node:node ./server ./server
ENV NODE_ENV=production
CMD [ "node","server/server.js"]
@evzpav
Copy link
Author

evzpav commented May 4, 2020

  • Once, in the Dokku machine, create a private key:
    ssh-keygen -t rsa
  • Then add key to Dokku:
    dokku ssh-keys:add gitlabkey ~/.ssh/id_rsa.pub
  • Add .gitlab-ci.yml to root of project.
  • Add a Dockerfile that Dokku will interpret like above. It can be as you like or any type of project.
  • On Gitlab.com in the project settings -> CI/CD -> Variables, add the following at least:
    SSH_PRIVATE_KEY (The private key generated in the Dokku machine: cat ~/.ssh/id_rsa)
    VM_IP (IP of the Dokku machine)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment