Git clone private repo in docker


Git clone private repo in docker

A simple how to guide to use git clone of a private repository inside docker container. With vuejs / nodejs app.

The package.json build script

  "build": "vue-cli-service build --port 8003", # for vuejs projects
  "start:prod": "babel-node ./src/index.js", # for nodejs projects with babel-node

env file

SSH_KEY="-----BEGIN OPENSSH PRIVATE KEY-----
YOUR CONTENT HERE
-----END OPENSSH PRIVATE KEY-----"

Vuejs app


# Choose and name our temporary image.
FROM alpine as intermediate

# Take an SSH key as a build argument.
ARG SSH_KEY

# Install dependencies required to git clone.
RUN apk update && \
    apk add --update git && \
    apk add --update openssh

# 1. Create the SSH directory.
RUN mkdir -p /root/.ssh/
# 2. Populate the private key file.
RUN echo "$SSH_KEY" > /root/.ssh/id_rsa
# 3. Set the required permissions.
RUN chmod -R 600 /root/.ssh/
# 4. Add github to our list of known hosts for ssh.
RUN ssh-keyscan -t rsa github.com >> ~/.ssh/known_hosts

# inject a datestamp arg which is treated as an environment variable and
# will break the cache for the next RUN command
ARG DATE_STAMP

# Clone a repository
RUN git clone [email protected]:USER/REPO_NAME.git

# default branch is master/main
# if you need to change the branch uncomment the following lines
# RUN cd /REPO_NAME && \
#    git checkout YOUR_BRANCH

## Build Stage ##

# pull the Node.js Docker image
FROM node:lts-alpine

# install simple http server for serving static content
RUN npm install -g http-server

# create the directory inside the container
WORKDIR /usr/src/app

# copy essential files to install dependencies
COPY --from=intermediate /REPO_NAME/app/package*.json .
COPY --from=intermediate /REPO_NAME/app/babel.config.js .
COPY --from=intermediate /REPO_NAME/app/vue.config.js .

# run npm install in our local machine
RUN npm install

# copy the generated modules and all other files to the container
COPY --from=intermediate /REPO_NAME/app/src/ ./src

# build app for production with minification
RUN npm run build

# our app is running on port 8003 within the container, so need to expose it
EXPOSE 8003

# the command that starts our app
CMD [ "http-server", "dist", "--port","8003" ]

# if you have a nodejs project, is not needed http-server,
# you can comment the line above and uncomment the next one
# CMD ["npm", "run", "start:prod"]

Docker-compose file

version: '3.3'

services:
  app:
    build:
      context: .
      dockerfile: app.Dockerfile
      args:
      - SSH_KEY=${SSH_KEY}
      - DATE_STAMP=${DATE_STAMP}
    container_name: app
    restart: always
    depends_on:
      - postgres
    ports:
      - "8003:8003"
    networks:
      - my-network

networks:
  my-network:
    driver: bridge

Newsletter


Related Posts

A Week in the Life of an Invoice Wrangler: Navigating Ridesharing and Food Delivery Chaos

As an app founder in the ridesharing and food delivery industry, I found myself knee-deep in invoice reports from companies like Bolt, Uber, Glovo, and Bolt Food

Free HTML templates list for Startups

Free HTML templates list for startup. A complete list with free resources to build your next startup's website and gain the traction to the sky.

Deal with client requests in SaaS

How to deal with client requests in Saas which are seeing only their interests, not the product interest.

The first client of LoyalXpert is not answering anymore

Trying to implement LoyalXpert app, I lost my first customer, he's not answering anymore

Experiments with Tiktok Ads

Recently tried out TikTok ads for the first time and here are some of my learnings and challenges

People don’t care about you, until they know you care about them.

People don’t care about you, until they know you care about them. The same happens in business, you need to take care of your clients.

The One Word That Can Ruin Your SaaS Business Anyone

As a SaaS founder, you probably know how important it is to have a clear and specific target market for your product.

How I got my digital certificate connected it with ANAF

How I got my digital certificate from certSIGN and connected it with ANAF

The Ultimate List of Company Directories to Boost Your Networking

Discover a wide range of company directories to boost your business's visibility and connect with potential clients.

Discover the Best Free AI Art Tools for Your Next Masterpiece

Explore a curated collection of the finest free AI art tools, designed to help you bring your artistic vision to life.