Giter Site home page Giter Site logo

godockci's Introduction

Example project to get the hang of the Go language, Docker containers, continuous integration with CircleCI.

This is built on Ubuntu Xenial (16.04). On Windows/Mac some tweaks probably needed.

Build status: CircleCI

Core Todo

  • Docker hello world
  • Hello http server
  • Unit test case
  • Development workflow with code reload/compile
  • Make a HTTP-request
  • Parse JSON
  • CircleCI integration
  • Production deployment
  • Contiuous deployment

More Todo

  • Use a goroutine
  • Use a channel
  • Use an HTML template
  • Serve static files
  • docker-compose.yml

Usage

Development

Assuming you have docker installed, clone this repo, cd to the project directory, build and run:

$ docker build -t hello-golang . $ docker run --volume=D:\go\path\src\github.com\sikharis\godockci -p 8080:3000 --rm --name my-running-app hello-golang

You should see "Starting server..." in the console, and "Hello world" in your browser if you navigate to localhost:8080

build -t tags the container with the given name --volume mounts the current directory to the docker container for code reloading -p binds your host port to docker port --rm removes the container after exit --name assigns a name

If you modify the source code, you should see the changes when refreshing your browser window.

Deployment

To deploy the project using the image in Docker Hub registry

  • install Docker on your server
  • docker pull sikharis/godockci
  • docker run -d -p 8080:3000 --rm --name golang-docker-circleci-example sikharis/godockci

This will run the container as a background job, listening to the OS port 8080. The container will be removed automatically when killed.

Contiuous deployment

To automatically update the running application, you can do something along the lines of:

#/bin/bash
echo "Pulling the latest version from registry"
docker pull sikharis/godockci
echo "Killing the running container"
docker kill golang-docker-circleci-example
echo "Preparing to run.."
docker run -d -p 8080:3000 --rm --name golang-docker-circleci-example sikharis/godockci

Here we give the container a name so we can kill it later. This script can be either triggered from the CI or run in cron for periodical updates (you should probably add a check whether a new version was actually pulled or not).

This is a naive solution, but probably enough to start with.

Technology links

Tutorials

godockci's People

Contributors

kharisup avatar

Watchers

 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.