README.md

July 15, 2022 ยท View on GitHub

Sewa Space App - Learn Golang

main-workflow

Overview

Golang

This project is documentation of my learning Golang with the best practice based on Standard Go Project Layout, by Kyle Quest.

Features

Usage

I use Makefile to simplify command line usage. Change line before build the application. Change binary filename according target operating system and target architecture.

BIN := goapp.exe
VERSION := 1.0.0
TARGET_OS := windows
TARGET_ARCH := amd64
TARGET OSTARGET ARCH
androidarm
linuxamd64
linuxarm
linuxarm64
linux386
windowsamd64
windows386
darwinamd64
darwinarm64
etc.etc.

The command is :

  • make build to build binary file
  • make clean to clean package and remove binary file
  • make docker it will execute command clean and build and then build image with docker command
  • make podman it will execute command clean and build and then build image with podman command

Note : Run your MySQL Database and Redis Server first before running the application

Run application directly

go run main.go

Work with containerize

Build binary and images

CGO_ENABLED=0 go build -o bin/goapp

docker build -t goapp:latest . -f build/Dockerfile

Run container using Docker

docker run -d --name goapp -p 8080:8080 --env-file=dev.env --network my-network goapp

Run container using Podman (Arch Linux)

Install dnsmasq and cni-plugins using package manager

sudo pacman -S dnsmasq cni-plugins

Looking for cni binary installed.

ls -l /opt/cni/bin
ls -l /usr/lib/cni

Using git, clone https://github.com/containers/dnsname.git see README_PODMAN.md and change line at Makefile

...
LIBEXECDIR ?= ${PREFIX}/cni/bin
...

Install with command sudo make install PREFIX=/opt

Change line again at Makefile

...
LIBEXECDIR ?= ${PREFIX}/lib/cni
...

Install with command sudo make install PREFIX=/usr

Enable cni in /etc/containers/containers.conf.

...
cni_plugin_dirs = [
    "/usr/local/libexec/cni",
    "/usr/libexec/cni",
    "/usr/local/lib/cni",
    "/usr/lib/cni",
    "/opt/cni/bin",
]
...

Create new network podman network create my-network

Update configuration my-network at $HOME/.config/cni/net.d/my-network.conflist

{
  "cniVersion": "0.4.0",
  "name": "my-network",
  "plugins": [
     ...
     {
        "type": "dnsname",
        "domainName": "my-network",
        "capabilities": {
           "aliases": true
        }
     }
     ...
  ]
}

Run container application

podman run -d --name goapp -p 8080:8080 --env-file=dev.env --network my-network goapp

Reference