Skip to content

Golang Project Orchestration

Vojtech Mašek edited this page Aug 19, 2019 · 2 revisions

Initialization

All Golang projects use Docker with Kubernetes as a development and production environments. Please follow the Golang installation guide to set up a proper environment. Nothing else will be needed.

Makefile

deps:
	docker-compose up deps

build: deps
	docker-compose build

dev:
	docker-compose up dev

deploy:
	docker-compose up deploy

clean:
	docker-compose down

🐞 Error: Missing separator. Stop.

Makefile only supports tabs, not spaces. When this error occurs, use your IDE to convert indent from spaces to tabs.

Dockerfile

FROM golang

# Need this for dependency management
RUN curl https://glide.sh/get | sh

# Test watcher
RUN go get github.com/smartystreets/goconvey

# goconvey port
EXPOSE 8080

docker-compose.yml

version: '2'
services:
  init:
    build: .
    image: ${ORGANIZATION}/${PROJECT_NAME}
    volumes:
      - .:${PROJECT_PATH}:Z
    working_dir: ${PROJECT_PATH}
    command: bash -c "glide init --non-interactive"
  dev:
    build: .
    image: ${ORGANIZATION}/${PROJECT_NAME}
    volumes:
      - .:${PROJECT_PATH}:Z
    working_dir: ${PROJECT_PATH}
    command: bash -c "glide install && go install ${CMD_GOPATH} && ${PROJECT_CMD_NAME}"
    ports:
      - 3000:3000
      - 3001:3001
      - 8080:8080
    links:
      - dev_db
  test-dev:
    build: .
    image: ${ORGANIZATION}/${PROJECT_NAME}
    volumes:
      - .:${PROJECT_PATH}:Z
    working_dir: ${PROJECT_PATH}
    command: bash -c ""
  empty:
    build: .
    image: ${ORGANIZATION}/${PROJECT_NAME}
    volumes:
      - .:${PROJECT_PATH}:Z
    working_dir: ${PROJECT_PATH}
    command: tail -f /dev/null
  dev_db:
    image: postgres
    container_name: ${PROJECT_NAME}_dev_db
    environment:
      - POSTGRES_USER=goo
      - POSTGRES_PASSWORD=goo
    ports:
      - 5432:5432

Development mode

This step can be executed every time you want to start developing the project. It automatically starts tests and re-execution when a file is saved.

$ make dev

Building docker images

Docker images for development should be automatically built. However, if you change Dockerfile, you need to manually rebuild the images.

$ make build

Cleaning images created by the project

$ make clean

Deploying project to server

@TODO

Clone this wiki locally