Skip to content

Commit

Permalink
Final V2 merge from 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
mtenrero committed Jul 5, 2018
2 parents c843acc + 5796949 commit ce52fdc
Show file tree
Hide file tree
Showing 32 changed files with 365 additions and 104 deletions.
14 changes: 14 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
FROM centos

LABEL MAINTAINER="Marcos Tenrero"

COPY ./releases/atq-director-linux-amd64 /atq/atq-amd64
COPY controller-config.docker.yaml /controller-config.yaml

RUN mkdir -p /gluster/storage

EXPOSE 8080

RUN cd /atq

ENTRYPOINT [ "/atq/atq-amd64" ]
4 changes: 4 additions & 0 deletions Gopkg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,7 @@
[[constraint]]
name = "github.com/dghubble/sling"
version = "1.1.0"

[[constraint]]
name = "github.com/mholt/archiver"
version = "2.0.0"
13 changes: 12 additions & 1 deletion Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ pipeline {
sh 'go get -u github.com/golang/lint/golint'
sh 'go get -u github.com/tebeka/go2xunit'
sh 'go get -u golang.org/x/tools/cmd/cover'
sh 'go get -u github.com/mattn/goveralls'
sh 'go get -u github.com/mtenrero/goveralls'
}
}

Expand All @@ -35,7 +35,18 @@ pipeline {
}
}

stage('Code Coverage') {
environment {
COVERTOKEN = credentials('coveralls-token')
}

steps {
sh 'cd $GOPATH/src/github.com/mtenrero/ATQ-Director && goveralls -coverprofile=coverage.txt -repotoken $COVERTOKEN'
}
}

stage('Build') {
when { expression { env.BRANCH_NAME == 'master' } }
steps {
sh 'cd $GOPATH/src/github.com/mtenrero/ATQ-Director && ./build.sh'
}
Expand Down
18 changes: 10 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Automation Test Queue (ATQ): Director

[![Build Status](http://ec2-35-177-127-126.eu-west-2.compute.amazonaws.com:8080/buildStatus/icon?job=ATQ/master)](http://ec2-35-177-127-126.eu-west-2.compute.amazonaws.com:8080/job/ATQ/job/master/)
[![Coverage Status](https://coveralls.io/repos/github/mtenrero/ATQ-Director/badge.svg)](https://coveralls.io/github/mtenrero/ATQ-Director)
[![Build Status](http://atq.mtenrero.com:8080/buildStatus/icon?job=ATQ/master)](http://atq.mtenrero.com:8080/job/ATQ/job/master/)
[![Coverage Status](https://coveralls.io/repos/github/mtenrero/ATQ-Director/badge.svg?branch=master)](https://coveralls.io/github/mtenrero/ATQ-Director?branch=master)
[![API Documentation](https://img.shields.io/badge/API-Documentation-orange.svg)](https://editor2.swagger.io/?url=https://raw.githubusercontent.com/mtenrero/ATQ-Director/master/swagger/swagger.yaml)

Automation Test Queue is a server-side binary which exposes a HTTP API and communicates with the Docker subsystem.
Expand Down Expand Up @@ -43,7 +43,8 @@ And the following versions will be `https:\\host:port\v2...`
You can specify which images are available to use with ATQ for security reasons with a YAML configuration file with the following structure:

```yaml
port: 9050
port: 8080
glusterPath: ...
images:
- imageName: mtenrero/jmeter
args:
Expand All @@ -57,6 +58,12 @@ images:
All images specified in this file will be pulled from the registries to make them available instantly when requested, so starting time may be increased in the first launch.
### GlusterPath
GlusterPath represents the path on the filsystem which is shared between Docker Swarm nodes in order to ATQ middlewara data be available from all nodes.
It has been tested with GlusterFS and Samba.
### **Images**
Images contain a list with the enabled images available to use with ATQ-Director
Expand Down Expand Up @@ -92,8 +99,3 @@ Any feature should be well documented and tested.

Godocs compatible code must be used.

## Disclaimer

**THIS IS AN INITIAL VERSION AND IT'S NOT COMPLETE !!**

_Guarantee it's not provided, use at your own risk._
9 changes: 2 additions & 7 deletions app/contexts.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 5 additions & 6 deletions app/test/task_testing.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions client/task.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions configLoader/controllerConfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package configLoader

// ControllerConfig contains all the configuration available for Controller Mode
type ControllerConfig struct {
Port string `yaml:"port"`
Images []Image `yaml:"images"`
Port string `yaml:"port"`
Images []Image `yaml:"images"`
GlusterPath string `yaml:"glusterpath"`
}
6 changes: 6 additions & 0 deletions configLoader/controllerConfig_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,9 @@ func TestLoadControllerConfigYamlFileErr(t *testing.T) {
t.Log(err)
}
}

func TestLoadControllerMalformedYaml(t *testing.T) {
_, err := LoadControllerConfigYaml("../Gopkg.toml")

assert.Error(t, err, "Error not fired reading malformed yaml")
}
11 changes: 11 additions & 0 deletions controller-config.docker.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
port: 8080
glusterpath: /gluster
images:
- imageName: mtenrero/jmeter
args:
- name: MODE
required: true
- name: TEST_NAME
required: false
- name: REMOTES
required: false
1 change: 1 addition & 0 deletions controller-config.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
port: 8080
glusterpath: /Users/marcostenrero/Documents/goProjects/src/github.com/mtenrero/ATQ-Director
images:
- imageName: mtenrero/jmeter
args:
Expand Down
64 changes: 60 additions & 4 deletions databind.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"errors"
"io"
"os"
"path/filepath"
Expand All @@ -10,6 +11,7 @@ import (
"strconv"

"github.com/goadesign/goa"
"github.com/mholt/archiver"
"github.com/mtenrero/ATQ-Director/app"
"github.com/mtenrero/ATQ-Director/persistance"
)
Expand Down Expand Up @@ -50,7 +52,7 @@ func (c *DatabindController) Upload(ctx *app.UploadDatabindContext) error {
reader, err := ctx.MultipartReader()

// Create files directory if doesn't exists
os.MkdirAll("./files", 0755)
err = os.MkdirAll(c.Persistance.GlusterPath+"/files", 0777)

// Reply with error message if errored
if err != nil {
Expand Down Expand Up @@ -88,9 +90,21 @@ func (c *DatabindController) Upload(ctx *app.UploadDatabindContext) error {
return ctx.UploadErrorError(&atqUploadError)
}

// Open file for later usage
fileName := part.FileName()
file, fileErr := os.OpenFile("./files/"+fileName, os.O_WRONLY|os.O_CREATE, 0666)

// Ensure file extension
isNotZip := ensureZip(fileName)
if isNotZip != nil {
errr := isNotZip.Error()
atqNotZip := app.AtqDatabindUploadError{
Error: &errr,
}

return ctx.TheFileDoesnTHaveAnAcceptedCompressionError(&atqNotZip)
}

// Open file for later usage
file, fileErr := os.OpenFile(c.Persistance.GlusterPath+"/files/"+fileName, os.O_WRONLY|os.O_CREATE, 0666)
if fileErr != nil {
errr := fileErr.Error()
atqUploadError := app.AtqDatabindUploadError{
Expand All @@ -99,16 +113,33 @@ func (c *DatabindController) Upload(ctx *app.UploadDatabindContext) error {
return ctx.UploadErrorError(&atqUploadError)
}

// Ensure file is closed if error occurred
defer file.Close()

// Copy mulitpart readed file content into FileSystem
io.Copy(file, part)

file.Close()

timestampUID := time.Now().Unix()
timestampUIDString := strconv.Itoa(int(timestampUID))

// Unzip File
directory, err := unzip(c.Persistance.GlusterPath, fileName, timestampUIDString)
if err != nil {
errr := err.Error()
atqError := app.AtqDatabindUploadError{
Error: &errr,
}

ctx.UploadErrorError(&atqError)
}

// Delete Original file
deleteFile(fileName)

// Save File to datastore
fullPath, _ := filepath.Abs("./files/" + fileName)
fullPath, _ := filepath.Abs(c.Persistance.GlusterPath + "/files/" + directory)
saveFileToDatastore(timestampUIDString, fullPath, c.Persistance)

atqUpload := app.AtqDatabindUpload{
Expand Down Expand Up @@ -141,3 +172,28 @@ func parseDatabind(collection *map[string]string) app.AtqDatabindUploadCollectio

return typeCollection
}

func ensureZip(fileName string) error {

var extension = filepath.Ext(fileName)

if extension != ".zip" {
return errors.New("The uploaded file is not a ZIP file")
}

return nil
}

func unzip(glusterPath, fileName, fileID string) (string, error) {
input := glusterPath + "/files/" + fileName
output := glusterPath + "/files/" + fileID
err := archiver.Zip.Open(input, output)

return output, err
}

func deleteFile(fileName string) error {
file := "./files/" + fileName
err := os.Remove(file)
return err
}
26 changes: 0 additions & 26 deletions dockerMiddleware/dnsrrWaiter.go

This file was deleted.

22 changes: 22 additions & 0 deletions dockerMiddleware/enumTypes_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package dockerMiddleware

import (
"testing"

"github.com/stretchr/testify/assert"
)

func TestEnums(t *testing.T) {
var service0 Service
var service1 Service
var service2 Service

service0 = 0
assert.Equal(t, "WORKER", service0.Name())

service1 = 1
assert.Equal(t, "MASTER", service1.Name())

service2 = 3
assert.Equal(t, "DISCOVERY", service2.Name())
}
Loading

0 comments on commit ce52fdc

Please sign in to comment.