Skip to content

Go R1 Day 47

progress🔗

  • worked with lefthook to run golang-lint tools and discovered how vast the configuration for this was, simplifying many of the other linting tools that was running seperately.
  • created some goyek tasks for bringing up and down docker compose stacks.
  • learned that file.Close() shouldn't be used with defer to avoid unsafe file handling operations.
// taskComposeDestroy tears down the docker stack including volumes
// this is using goyek task framework for Make alternative
func taskComposeDestroy() goyek.Task {
  return goyek.Task{
    Name:  "compose-destroy",
    Usage: "remove stack with prejudice",
    Action: func(tf *goyek.TF) {
      dcBase := filepath.Join(BuildRoot, "docker", "docker-compose.myservice.yml")
      dcMySQL := filepath.Join(BuildRoot, "docker", "docker-compose.mysql.yml")
      compose := tf.Cmd("docker", "compose", "-f", dcBase, "-f", dcMySQL, "down", "--volumes", "--remove-orphans")
      if err := compose.Run(); err != nil {
        tf.Fatalf(":heavy_exclamation_mark: docker-compose down failed: [%v]", err)
      }
      tf.Log(":white_check_mark: docker-compose ran successfully")
    },
  }
}