From bc969379958783e475c3f9607125f47c0d684339 Mon Sep 17 00:00:00 2001 From: Andy LeTourneau Date: Sun, 5 Aug 2018 11:33:45 +0000 Subject: [PATCH] Setup docker --- .gitignore | 6 +++- .gitlab-ci.yml | 57 +++++++++++++++++++++++++++++++++++++ Dockerfile | 23 +++++++++++++++ README.md | 25 +++------------- actionHandler_test.go | 22 ++++++++++++++ dep.yml | 27 ++++++++++++++++++ docker/docker-entrypoint.sh | 5 ++++ 7 files changed, 143 insertions(+), 22 deletions(-) create mode 100755 .gitlab-ci.yml create mode 100755 Dockerfile create mode 100755 actionHandler_test.go create mode 100755 dep.yml create mode 100755 docker/docker-entrypoint.sh diff --git a/.gitignore b/.gitignore index f1d11fe..a3b25a9 100755 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,7 @@ .idea depcharge -*.exe \ No newline at end of file +*.exe + +bin +pkg +src diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml new file mode 100755 index 0000000..7a9b41d --- /dev/null +++ b/.gitlab-ci.yml @@ -0,0 +1,57 @@ +image: golang:1.10-alpine + +stages: +- init +- test +- build + +init: + stage: init + script: + - export GOPATH=$(pwd) + - apk update && apk add git + - go get github.com/ghodss/yaml github.com/cbroglie/mustache/... github.com/stretchr/testify + artifacts: + paths: + - bin/ + - pkg/ + - src/ + + +test: + stage: test + dependencies: + - init + coverage: '/coverage: \d+\.\d+\%/' + script: + - export GOPATH=$(pwd) + - go test -cover + + +build: + stage: build + dependencies: + - init + script: + - export GOPATH=$(pwd) + - go build . + artifacts: + paths: + - depcharge + + +build-docker: + image: docker:latest + stage: build + services: + - docker:dind + script: + - docker login -u gitlab-ci-token -p $CI_JOB_TOKEN $CI_REGISTRY + - docker build -t $CI_REGISTRY_IMAGE:latest . + + # Ensure the container can run properly + - docker run $CI_REGISTRY_IMAGE:latest + + - docker push $CI_REGISTRY_IMAGE:latest + only: + - master diff --git a/Dockerfile b/Dockerfile new file mode 100755 index 0000000..e94e045 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,23 @@ +FROM golang:1.10-alpine as go + +RUN apk update \ + && apk add git \ + && rm -rf /var/cache/apk/* + +RUN go get \ + github.com/ghodss/yaml \ + github.com/cbroglie/mustache/... \ + github.com/stretchr/testify + +COPY . /go/src/depcharge +WORKDIR /go/src/depcharge + +RUN go test . +RUN go build . + +FROM alpine:latest +COPY --from=go /go/src/depcharge/depcharge /bin/depcharge +RUN mkdir /mount +WORKDIR /mount +ENTRYPOINT ["depcharge"] +CMD ["--help"] diff --git a/README.md b/README.md index c5366a9..333eb88 100755 --- a/README.md +++ b/README.md @@ -2,9 +2,6 @@ DepCharge is a tool designed to help orchestrate the execution of commands across many directories at once. -* [GitHub is the public-access repository](https://github.com/centerorbit/depcharge) -* [GitLab is where development & pipelines occur](https://gitlab.com/centerorbit/depcharge) - ## Introduction A medium-to-large sized project (especially when using a microservice architecture) will consist of 3 or more separate repositories, and rely on a variety of package managers depending on the various languages chosen for each service. Typically, these repos must be managed, tracked, and released in some semblance of unison so that the dependant service calls can be understood and responded to appropriately. @@ -92,26 +89,12 @@ Will run `composer install` across any composer dependencies that have either th And much more! -## ToDo: -### Before v1.0 -* Setup sample project for example and test -* Build Pipeline - -### Wish List -1. Test support of YAML anchors -2. Secrets managment? -3. docker-compose handler -4. Implement channels / goroutines -5. Mechanism to perform _other_ types of commands to 'kind's rather than `kind` -6. Need a "literal" flag, to turn off templating? -7. Find a way to "stream" output to terminal? -8. Test Coverage -9. Better Logging & Verbose flag - - ## Additional Resources -* https://www.atlassian.com/blog/git/alternatives-to-git-submodule-git-subtree +* https://mustache.github.io/ +## Contributing +* [GitLab is where development & pipelines occur](https://gitlab.com/centerorbit/depcharge) +* [GitHub is the public-access repository](https://github.com/centerorbit/depcharge) ## License diff --git a/actionHandler_test.go b/actionHandler_test.go new file mode 100755 index 0000000..282ef8e --- /dev/null +++ b/actionHandler_test.go @@ -0,0 +1,22 @@ +package main + +import ( + "testing" + "github.com/stretchr/testify/assert" + "reflect" +) + +func TestFindActionHandler(t *testing.T) { + var handler func([]Dep, Perform) + + handler = findActionHandler("git") + functionEqual(t, gitActionHandler, handler) + handler = findActionHandler("secret") + functionEqual(t, secretesActionHandler, handler) + handler = findActionHandler("other") + functionEqual(t, defaultActionHandler, handler) +} + +func functionEqual(t *testing.T, expected func([]Dep, Perform), actual func([]Dep, Perform)){ + assert.Equal(t, reflect.ValueOf(expected), reflect.ValueOf(actual)) +} \ No newline at end of file diff --git a/dep.yml b/dep.yml new file mode 100755 index 0000000..51d007f --- /dev/null +++ b/dep.yml @@ -0,0 +1,27 @@ +deps: +- name: depcharge + kind: project + location: ./ + deps: + - name: gitlab + kind: git + location: + params: + repo: git@gitlab.com:centerorbit/depcharge.git + - name: github + kind: git + location: + params: + repo: git@github.com:centerorbit/depcharge.git + - name: yaml-parser + kind: go + params: + get: github.com/ghodss/yaml + - name: mustache + kind: go + params: + get: github.com/cbroglie/mustache/... + - name: assertions + kind: go + params: + get: github.com/stretchr/testify diff --git a/docker/docker-entrypoint.sh b/docker/docker-entrypoint.sh new file mode 100755 index 0000000..e377e6a --- /dev/null +++ b/docker/docker-entrypoint.sh @@ -0,0 +1,5 @@ +#!/bin/bash + + + +exec "$@" \ No newline at end of file