Skip to content

Instantly share code, notes, and snippets.

# ---------------------------------------------------------------------
# The first stage container, for building the application
# ---------------------------------------------------------------------
FROM golang:1.12.1-stretch as builder
COPY . /app
# Add the keys
ARG bitbucket_id
ENV bitbucket_id=$bitbucket_id
git config \
--global \
url."https://oauth2:${personal_access_token}@privategitlab.com".insteadOf \
"https://privategitlab.com"
#or
git config \
--global \
url."https://${user}:${personal_access_token}@privategitlab.com".insteadOf \
git config \
--global \
url."https://${bitbucket_id}:${bitbucket_token}@privatebitbucket.com".insteadOf \
"https://privatebitbucket.com"
git config \
--global \
url."https://${user}:${personal_access_token}@github.com".insteadOf \
"https://github.com"
@timjonesdev
timjonesdev / sniff.go
Created February 18, 2019 23:50
A simple health check Go application
package main
import (
"fmt"
"net/http"
"os"
)
func main() {
// Could/should make this configurable
git config \
--global \
url."git@github.com".insteadOf \
"https://github.com"
version: '3.0'
services:
app:
container_name: my_go_app_container
build:
# context can/may/will be different per-project setup
context: ../
dockerfile: GitDockerfile
args:
- bitbucket_id=private_user
@timjonesdev
timjonesdev / docker-cleanup.sh
Created June 29, 2019 04:42
A cleanup script for docker resources, if you don't have `docker system prune` available. WARNING: This will delete all containers, images, and volumes.
#!/usr/bin/env bash
echo "Running docker cleanup script"
echo "Stopping all containers"
docker stop $(docker ps -a -q) # Stop all containers
echo "Removing stopped containers"
docker rm $(docker ps -a -q) # Remove all stopped containers
@timjonesdev
timjonesdev / static.go
Created September 17, 2019 21:56
A static file server that gracefully handles resource not found errors and passes requests to the client.
func StaticFileServer(r chi.Router, public string, static string) {
// everything up to the r.Get call is executed the first time the function is called
if strings.ContainsAny(public, "{}*") {
panic("FileServer does not permit URL parameters.")
}
root, _ := filepath.Abs(static)
if _, err := os.Stat(root); os.IsNotExist(err) {
panic("Static Documents Directory Not Found")
@timjonesdev
timjonesdev / MongoDockerfile
Last active November 28, 2019 16:43
A MongoDB Dockerfile which enables a single-node replicaset
FROM mongo:4.0
# files used to initialize the database
COPY ./init-db.d/ /docker-entrypoint-initdb.d
# add this command to a js file in the init directory
# formatted on newlines for better readability
RUN echo "rs.initiate(
{
_id: 'rs0',