anuragdhingra / pdocker-go

Implementation of contanerizing a golang app using private repositories as imports

Home Page:https://bit.ly/2UnBuJG

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

pdocker-go

Blog on medium: Containerize a golang app using private GitHub repos as import packages

This repo is the basic implementation of containerizing a golang app via docker using private repos as import packages. The problem we encounter is to provide the required ssh_key while fetching these packages using go get to containerize them. You can do it by adding the following to your Dockerfile:

RUN mkdir -p /root/.ssh && \
    echo "$SSH_KEY" > /root/.ssh/id_rsa && \
    chmod 0600 /root/.ssh/id_rsa && \
    eval `ssh-agent` && \
    ssh-add /root/.ssh/id_rsa && \
    ssh-keyscan github.com >> /root/.ssh/known_hosts && \
    echo "[url \"ssh://git@github.com/\"]\n\tinsteadOf = https://github.com/" >> /root/.gitconfig && \
    echo "Host github.com\n\tStrictHostKeyChecking no\n" >> /root/.ssh/config

Steps to follow:

  • Get the project using go get :
go get github.com/anuragdhingra/pdocker-go
  • Change directory:
cd $GOPATH/src/github.com/anuragdhingra/pdocker-go
  • Run make command, if you have default github ssh_key_path as ~/.ssh/id_rsa:
make build-dev

Use the argument optional argument ssh_key_path in case of custom paths:

make build-dev ssh_key_path=~/.ssh/${SSH_KEY_FILENAME}

NOTE: Make sure you have the same public part of the key added to your github account here.

  • The make command will use your ssh_key make authenticated requests inside the container environment, spin up an elasticsearch(localhost:9200) instance, a mysql(localhost:3306) instance and once both of them are ready will spin an instance of your application(localhost:8080) which will try to connect to the former spun containers. Using the wait-for-it.sh script to coordinate the containers.

About

Implementation of contanerizing a golang app using private repositories as imports

https://bit.ly/2UnBuJG


Languages

Language:Shell 71.9%Language:Go 15.4%Language:Dockerfile 9.9%Language:Makefile 2.8%