Skip to content

This is an experiment with deploying a basic Golang API

Notifications You must be signed in to change notification settings

amichael7/go-api-toy

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Go Toy API: Simple Golang API Example in a Docker container

A template project to create a Docker image for a Go application. The example application exposes an HTTP endpoint and

This project is based on miguno/golang-docker-build-tutorial The Docker build uses a multi-stage build setup to minimize the size of the generated Docker image. The Go build uses dep for dependency management.

Requirements

The only requirement for this running this example is that docker is installed.

Usage

  1. Use the included script to build the image inside the docker container
./app build
  1. Use the included script to run the image inside a docker container
./app run

# or you can specify a port number
# ./app run -p 3000

Explanation

Two-stage build. The code is written on the local system then copied into the docker builder. The builder is a full golang docker image that is used to compile the code. The builder image is then discarded and the compiled binaries are placed into a minimal image (called scratch).

shell script. In order to facilitate the quick deployment of the app, I wrote a shell script for convenience to handle some of the messy internal workings. The internal configuration (specifically the container internal port number, image name, and image tag) are all configured within the app script.

Tricks

Because I don't like hardcoding names into my dockerfile, I'm using python to do template substitution in the dockerfile. This is not standard but I want all the docker configuration to be ingested through some kind of logic to make sure everything is working as intended.

Notes

If you need SSL certificates for HTTPS, replace FROM SCRATCH in the Docker file with:

FROM alpine:3.7
RUN apk --no-cache add ca-certificates

Todo

  • Add the dockerfile templating tool
  • Get the image to build successfully
  • Launch a working hello world container

About

This is an experiment with deploying a basic Golang API

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published