Skip to content

Commit

Permalink
Merge pull request #19 from 030/17-generic
Browse files Browse the repository at this point in the history
[#17] Uploading and downloading of generic artifacts.
  • Loading branch information
030 authored Sep 21, 2022
2 parents b770370 + 4db7374 commit 1c16d65
Show file tree
Hide file tree
Showing 16 changed files with 540 additions and 104 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ jobs:
echo "Version: ${version}"
echo "Checking README.md..."
grep "yaam:${version}" docs/usage/DOCKER.md
echo "Checking k8s-openshift deployment..."
grep "yaam:${version}" deployments/k8s-openshift/deploy.yml
- name: Create release
run: ./scripts/build.sh
env:
Expand Down
20 changes: 15 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
[![DevOps SE Questions](https://img.shields.io/stackexchange/devops/t/yaam.svg?logo=stackexchange)](https://devops.stackexchange.com/tags/yaam)
[![ServerFault SE Questions](https://img.shields.io/stackexchange/serverfault/t/yaam.svg?logo=serverfault)](https://serverfault.com/tags/yaam)
![Docker Pulls](https://img.shields.io/docker/pulls/utrecht/yaam.svg)
[![yaam on stackoverflow](https://img.shields.io/badge/stackoverflow-community-orange.svg?longCache=true&logo=stackoverflow)](https://stackoverflow.com/tags/yaam)
![Issues](https://img.shields.io/github/issues-raw/030/yaam.svg)
![Pull requests](https://img.shields.io/github/issues-pr-raw/030/yaam.svg)
![Total downloads](https://img.shields.io/github/downloads/030/yaam/total.svg)
Expand Down Expand Up @@ -35,16 +36,25 @@
[![BCH compliance](https://bettercodehub.com/edge/badge/030/yaam?branch=main)](https://bettercodehub.com/results/030/yaam)
[![GolangCI](https://golangci.com/badges/github.com/golangci/golangci-web.svg)](https://golangci.com/r/github.com/030/yaam)
[![codebeat badge](https://codebeat.co/badges/af6b1a01-df2c-40e7-bfb1-13ec0bb90087)](https://codebeat.co/projects/github-com-030-yaam-main)
[![Conventional Commits](https://img.shields.io/badge/Conventional%20Commits-1.0.0-%23FE5196?logo=conventionalcommits&logoColor=white)](https://conventionalcommits.org)
[![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg)](https://github.com/semantic-release/semantic-release)

[GoDoc]: https://godoc.org/github.com/030/yaam
[GoDoc Widget]: https://godoc.org/github.com/030/yaam?status.svg

Yet Another Artifact Manager (YAAM):
Although there are many artifact managers, like Artifactory, Nexus3 and
Verdaccio, they are either monoliths, consume a lot of resources
(memory and CPU), lack Infrastructure as Code (IaC) or do not support all kind
of artifact types. Yet Another Artifact Manager (YAAM):

* an artifact manager like Artifactory or Nexus3.
* without UI.
* lower CPU and Memory usage.
* supports Maven artifact publication and 3rdparty repository caching.
* is an artifact manager like Artifactory, Nexus3 or Verdaccio.
* enforces IaC.
* has no UI.
* does not have a database.
* scales horizontally.
* supports downloading and publication of Generic, Maven and NPM artefacts,
preserves NPM and Maven packages from public repositories and unifies Maven
repositories.

## Usage

Expand Down
47 changes: 40 additions & 7 deletions cmd/yaam/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,16 @@ import (
"io"
"net/http"
"os"
"strconv"
"time"

"github.com/030/yaam/internal/api"
"github.com/030/yaam/internal/artifact"
"github.com/030/yaam/internal/pkg/project"
"github.com/gorilla/mux"
log "github.com/sirupsen/logrus"
)

const (
serverLogMsg = "check the server logs"
port = 25213
)
const serverLogMsg = "check the server logs"

var Version string

Expand Down Expand Up @@ -90,6 +87,35 @@ func mavenGroup(w http.ResponseWriter, r *http.Request) {
}
}

func genericArtifact(w http.ResponseWriter, r *http.Request) {
defer func() {
if err := r.Body.Close(); err != nil {
panic(err)
}
}()

if err := api.Validation(r.Method, r, w); err != nil {
httpInternalServerErrorReadTheLogs(w, err)
return
}

g := artifact.Generic{Request: r, RequestBody: r.Body, RequestURI: r.RequestURI, ResponseWriter: w}
if r.Method == "POST" {
var p artifact.Publisher = g
if err := p.Publish(); err != nil {
httpInternalServerErrorReadTheLogs(w, err)
return
}
return
}

var ar artifact.Reader = g
if err := ar.Read(); err != nil {
httpNotFoundReadTheLogs(w, err)
return
}
}

func npmArtifact(w http.ResponseWriter, r *http.Request) {
defer func() {
if err := r.Body.Close(); err != nil {
Expand Down Expand Up @@ -126,6 +152,12 @@ func npmArtifact(w http.ResponseWriter, r *http.Request) {
}

func status(w http.ResponseWriter, r *http.Request) {
defer func() {
if err := r.Body.Close(); err != nil {
panic(err)
}
}()

if _, err := io.WriteString(w, "ok"); err != nil {
httpNotFoundReadTheLogs(w, err)
return
Expand All @@ -144,21 +176,22 @@ func main() {
}

r := mux.NewRouter()
r.HandleFunc("/generic/{repo}/{artifact:.*}", genericArtifact)
r.HandleFunc("/maven/groups/{name}/{artifact:.*}", mavenGroup)
r.HandleFunc("/maven/{repo}/{artifact:.*}", mavenArtifact)
r.HandleFunc("/npm/{repo}/{artifact:.*}", npmArtifact)
r.HandleFunc("/status", status)

srv := &http.Server{
Addr: "0.0.0.0:" + strconv.Itoa(port),
Addr: "0.0.0.0:" + project.PortString,
// Good practice to set timeouts to avoid Slowloris attacks.
WriteTimeout: time.Second * 120,
ReadTimeout: time.Second * 180,
IdleTimeout: time.Second * 240,
Handler: r, // Pass our instance of gorilla/mux in.
}

log.Infof("Starting YAAM version: '%s' on localhost on port: '%d'...", Version, port)
log.Infof("Starting YAAM version: '%s' on localhost on port: '%d'...", Version, project.Port)
if err := srv.ListenAndServe(); err != nil {
log.Fatal(err)
}
Expand Down
Loading

0 comments on commit 1c16d65

Please sign in to comment.