Giter VIP home page Giter VIP logo

containerized-go-dev's Introduction

Continuous Integration

Example Containerized Go Development Environment

This repository contains an example Go project with a containerized development environment. The example project is a simple CLI tool that echos back its inputs.

Why should I containerize my development environment?

There are several advantages to containerizing your development environment:

  • You make explicit the tools and versions of tools required to develop your project
  • Your builds will be more deterministic and reproducible

These will both make it easier for people to collaborate on your project, as everyone will have the same environment, and make it easier to debug things like CI failures.

Prerequisites

The only requirements to build and use this project are Docker and make. The latter can easily be substituted with your scripting tool of choice.

You will also need to enable the BuildKit builder in the Docker CLI. This can be done by setting DOCKER_BUILDKIT=1 in your environment.

macOS

  • Install Docker Desktop
  • Ensure that you have make (included with Xcode)
  • Run export DOCKER_BUILDKIT=1 in your terminal or add to your shell initialization scripts

Windows

  • Install Docker Desktop
  • Ensure that you have make
  • If using PowerShell, run $env:DOCKER_BUILDKIT=1
  • If using command prompt, run set DOCKER_BUILDKIT=1

Linux

  • Install Docker
  • Ensure that you have make
  • Run export DOCKER_BUILDKIT=1 in your terminal or add to your shell initialization scripts

Getting started

Building the project will output a static binary in the bin/ folder. The default platform is for macOS but this can be changed using the PLATFORM variable:

$ make                        # build for your host OS
$ make PLATFORM=darwin/amd64  # build for macOS
$ make PLATFORM=windows/amd64 # build for Windows x86_64
$ make PLATFORM=linux/amd64   # build for Linux x86_64
$ make PLATFORM=linux/arm     # build for Linux ARM

You can then run the binary, which is a simple echo binary, as follows:

$ ./bin/example hello world!
hello world!

To run the unit tests run:

$ make unit-test

To run the linter:

$ make lint

There's then a helpful test alias for running both the linter and the unit tests:

$ make test

Structure of project

Dockerfile

The Dockerfile codifies all the tools needed for the project and the commands that need to be run for building and testing it.

Makefile

The Makefile is purely used to script the required docker build commands as these can get quite long. You can replace this file with a scripting language of your choice.

CI

The CI is configured in the ci.yaml file. By containerizing the toolchain, the CI relies on the toolchain we defined in the Dockerfile and doesn't require any custom setup.

Related Blog

Containerize your local Go developer environment series

Read more

containerized-go-dev's People

Contributors

chris-crone avatar kokizzu avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.