Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
jakesylvestre committed Mar 4, 2021
0 parents commit e8a0e9c
Show file tree
Hide file tree
Showing 24 changed files with 976 additions and 0 deletions.
20 changes: 20 additions & 0 deletions .github/ISSUE_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
### Background

Describe your issue here.

### Your environment

* version of `docker-utils`
* any other relevant environment details

### Steps to reproduce

Tell us how to reproduce this issue. Please provide stacktraces and links to code in question.

### Expected behaviour

Tell us what should happen

### Actual behaviour

Tell us what happens instead
9 changes: 9 additions & 0 deletions .github/renovate.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"extends": ["config:base"],
"packageRules": [
{
"updateTypes": ["minor", "patch", "pin", "digest"],
"automerge": true
}
]
}
14 changes: 14 additions & 0 deletions .github/stale.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Number of days of inactivity before an issue becomes stale
daysUntilStale: 30
# Number of days of inactivity before a stale issue is closed
daysUntilClose: false
# Label to use when marking an issue as stale
staleLabel: stale
# Comment to post when marking an issue as stale. Set to `false` to disable
markComment: >
This issue has been automatically marked as stale because it has not had
recent activity. It will be closed if no further activity occurs. Thank you
for your contributions.
# Comment to post when closing a stale issue. Set to `false` to disable
closeComment: false

67 changes: 67 additions & 0 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
name: goreleaser

on:
push:
branches:
- master
jobs:
goreleaser:
runs-on: ubuntu-latest
if: "! contains(toJSON(github.event.commits.*.message), '[ci skip]')"
steps:
-
name: Checkout
uses: actions/checkout@v2
-
name: Unshallow
run: git fetch --prune --unshallow
- name: Bump version and push tag
uses: anothrNick/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.FOSS_PACKAGE_TOKEN }}
WITH_V: true
- name: Bump version and push tag (no v)
uses: anothrNick/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.FOSS_PACKAGE_TOKEN }}
WITH_V: false
-
name: Set up Go
uses: actions/setup-go@v2
with:
go-version: 1.14
- name: login
run: echo $FOSS_PACKAGE_TOKEN | docker login -u $FOSS_PACKAGE_USER --password-stdin ghcr.io
env:
FOSS_PACKAGE_TOKEN: ${{ secrets.FOSS_PACKAGE_TOKEN }}
FOSS_PACKAGE_USER: ${{ secrets.FOSS_PACKAGE_USER }}
-
name: Run GoReleaser
uses: goreleaser/goreleaser-action@v2
with:
version: v0.143.0
args: release --rm-dist
env:
GITHUB_TOKEN: ${{ secrets.FOSS_PACKAGE_TOKEN }}
-
name: Notify slack success
if: success()
env:
SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }}
uses: voxmedia/github-action-slack-notify-build@v1
with:
channel: activity
status: SUCCESS
color: good

-
name: Notify slack fail
if: failure()
env:
SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }}
uses: voxmedia/github-action-slack-notify-build@v1
with:
channel: activity
status: FAILED
color: danger

33 changes: 33 additions & 0 deletions .github/workflows/notify.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# notifies the entropy_rocks_commits channel of events
name: "Irc Notification"
on: [push, pull_request, create]

jobs:
test:
runs-on: ubuntu-latest
steps:
- name: irc push
uses: rectalogic/notify-irc@v1
if: github.event_name == 'push'
with:
channel: "#entropy_rocks_commits"
nickname: entropy-github-notifier
message: |
${{ github.actor }} pushed ${{ github.event.ref }} ${{ github.event.compare }}
${{ join(github.event.commits.*.message) }}
- name: irc pull request
uses: rectalogic/notify-irc@v1
if: github.event_name == 'pull_request'
with:
channel: "#entropy_rocks_commits"
nickname: my-github-notifier
message: |
${{ github.actor }} opened PR ${{ github.event.pull_request.html_url }}
- name: irc tag created
uses: rectalogic/notify-irc@v1
if: github.event_name == 'create' && github.event.ref_type == 'tag'
with:
channel: "#entropy_rocks_commits"
nickname: my-github-notifier
message: |
${{ github.actor }} tagged ${{ github.repository }} ${{ github.event.ref }}
41 changes: 41 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: test

on:
pull_request:
push:
branches:
- master

jobs:
test:
if: "!contains(toJSON(github.event.commits.*.message), '[ci skip]')"
strategy:
matrix:
go-version: [1.13.x, 1.14.x, 1.15.x]
platform: [ubuntu-latest, macos-latest]
runs-on: ${{ matrix.platform }}
steps:
- name: Install Go
uses: actions/setup-go@v2
with:
go-version: ${{ matrix.go-version }}
- name: Install go-acc
shell: bash
run: go get -u github.com/ory/go-acc
env:
GO111MODULE: "on"
- name: Checkout code
uses: actions/checkout@v2
- name: Install Linters
run: "curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh -s -- -b $(go env GOPATH)/bin v1.35.2"
- name: Test
run: ./goclean.sh
- name: Send coverage
uses: shogo82148/actions-goveralls@v1
with:
github-token: ${{ secrets.github_token }}
path-to-profile: profile.cov
- name: Build
env:
GO111MODULE: "on"
run: go build ./...
27 changes: 27 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# IDE Files
.idea/
# Binaries for programs and plugins
*.exe
*.exe~
*.dll
*.so
*.dylib

# Test binary, built with `go test -c`
*.test

# Output of the go coverage tool, specifically when used with LiteIDE
*.out
*.cov

# Dependency directories (remove the comment below to include it)
vendor/
gcloud.json
out.version

# make sure to change "microservice" to whatever the name
# of your actual executable file is.
microservice
service
main
vendor/
21 changes: 21 additions & 0 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
project_name: docker-utils-project
build:
skip: true
checksum:
name_template: checksums.txt
snapshot:
name_template: '{{ .Tag }}-next'
changelog:
sort: asc
filters:
exclude:
- '^docs:'
- '^test:'
release:
github:
owner: xplorfin
name: docker-utils

# add a source archive at release time
source:
enabled: true
20 changes: 20 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
Copyright (c) 2019-2021 [Entropy](http://entropy.rocks/) and others

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
72 changes: 72 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# Constants
GHCR_URL=ghcr.io/xplorfin

# variables related to your microservice
# change SERVICE_NAME to whatever you're naming your microservice
SERVICE_NAME=docker-utils
# name of output binary
BINARY_NAME=updater

# latest git commit hash
LATEST_COMMIT_HASH=$(shell git rev-parse HEAD)

# go commands and variables
GO=go
GOB=$(GO) build
GOT=$(GO) test
GOM=$(GO) mod

# environment variables related to
# cross-compilation.
GOOS_MACOS=darwin
GOOS_LINUX=linux
GOARCH=amd64

# currently installed/running Go version (full and minor)
GOVERSION=$(shell go version | grep -Eo '[1-2]\.[[:digit:]]{1,3}\.[[:digit:]]{0,3}')
MINORVER=$(shell echo $(GOVERSION) | awk '{ split($$0, array, ".") } {print array[2]}')

# Color code definitions
# Note: everything is bold.
GREEN=\033[1;38;5;70m
BLUE=\033[1;38;5;27m
LIGHT_BLUE=\033[1;38;5;32m
MAGENTA=\033[1;38;5;128m
RESET_COLOR=\033[0m

COLORECHO = $(1)$(2)$(RESET_COLOR)

macos: check-version gomvendor build-macos

linux: check-version gomvendor build-linux

# Makes sure you're running a version of go which supports
# go modules.
check-version:
ifeq ($(shell [[ $(MINORVER) -lt 11 ]] && BADVER=yes || BADVER=no; echo $$BADVER), yes)
@echo "Installed go version ($(GOVERSION)) is lower than 1.11."
@echo "Go >= 1.11 is required for use with Go modules."
@echo "Please update your go version."
exit 5
else
ifeq ($(shell [[ $(MINORVER) -lt 14 ]] && LOWVER=yes || LOWVER=no; echo $$LOWVER), yes)
@echo "Installed go version ($(GOVERSION)) is lower than 1.14."
@echo "Things will still work, but you should definitely update your installed Go version."
endif
endif

test:
$(GOT) ./...

gomvendor:
$(GOM) tidy
$(GOM) vendor

build-macos:
env GOOS=$(GOOS_MACOS) GOARCH=$(GOARCH) \
$(GOB) -mod vendor -o $(BINARY_NAME)

build-linux:
env GOOS=$(GOOS_LINUX) GOARCH=$(GOARCH) \
$(GOB) -mod vendor -o $(BINARY_NAME)

14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[![Coverage Status](https://coveralls.io/repos/github/xplorfin/docker-utils/badge.svg?branch=master)](https://coveralls.io/github/xplorfin/docker-utils?branch=master)
[![Renovate enabled](https://img.shields.io/badge/renovate-enabled-brightgreen.svg)](https://app.renovatebot.com/dashboard#github/xplorfin/docker-utils)
[![Build status](https://github.com/xplorfin/docker-utils/workflows/test/badge.svg)](https://github.com/xplorfin/docker-utils/actions?query=workflow%3Atest)
[![Build status](https://github.com/xplorfin/docker-utils/workflows/goreleaser/badge.svg)](https://github.com/xplorfin/docker-utils/actions?query=workflow%3Agoreleaser)
[![](https://godoc.org/github.com/xplorfin/docker-utils?status.svg)](https://godoc.org/github.com/xplorfin/docker-utils)
[![Go Report Card](https://goreportcard.com/badge/github.com/xplorfin/docker-utils)](https://goreportcard.com/report/github.com/xplorfin/docker-utils)

# What is this?

This is a helper library for interacting with docker, particularly in continuous integration workflows

## Note:

This library was open sourced as a dependency for another project. While this is functional, documentation may be lacking for a bit.
38 changes: 38 additions & 0 deletions client.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package docker

import (
"context"

"github.com/docker/docker/api/types"

"github.com/google/uuid"

"github.com/docker/docker/client"
)

const Driver = "local"

type Client struct {
*client.Client
Ctx context.Context
SessionId string
// configured authentication goes here
RegistryAuth *types.AuthConfig
}

func NewDockerClient() Client {
ctx := context.Background()
cli, err := client.NewClientWithOpts(client.FromEnv, client.WithAPIVersionNegotiation())
if err != nil {
panic(err)
}
sessionId, err := uuid.NewRandom()
if err != nil {
panic(err)
}
return Client{
Client: cli,
Ctx: ctx,
SessionId: sessionId.String(),
}
}
Loading

0 comments on commit e8a0e9c

Please sign in to comment.