Skip to content

Commit

Permalink
feat(docker): Starting docker support
Browse files Browse the repository at this point in the history
Signed-off-by: Vincent Boutour <[email protected]>
  • Loading branch information
ViBiOh committed May 22, 2021
1 parent 88bbfcf commit de79d66
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 5 deletions.
13 changes: 13 additions & 0 deletions cmd/ketchup/templates/ketchup.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ <h2 class="header">Create ketchup</h2>
</label>
<input id="create-kind-helm" type="radio" name="kind" value="helm">
</span>
<span class="flex-grow center">
<label for="create-kind-docker" class="block">
<img class="icon icon-large clickable" src="/svg/docker?fill=silver" alt="Docker icon">
</label>
<input id="create-kind-docker" type="radio" name="kind" value="docker">
</span>
</p>

<p class="padding no-margin">
Expand Down Expand Up @@ -76,6 +82,13 @@ <h2 class="header">Create ketchup</h2>
nameInput.classList.remove("hidden");
}
});

document.getElementById('create-kind-docker').addEventListener('change', (e) => {
if (e.target.value === 'docker') {
repositoryInput.placeholder = 'vibioh/ketchup';
nameInput.classList.add("hidden");
}
});
</script>
{{ end }}

Expand Down
6 changes: 4 additions & 2 deletions cmd/ketchup/templates/public.html
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,10 @@
{{ end}}

{{ define "header-part" }}
{{ if ne .Root "/" }}
<a href="#create-modal" class="button bg-primary">Create</a>
{{ with .Root }}
{{ if ne . "/" }}
<a href="#create-modal" class="button bg-primary">Create</a>
{{ end }}
{{ end }}
{{ end }}

Expand Down
3 changes: 3 additions & 0 deletions cmd/ketchup/templates/svg.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 304 351"><mask id="a" fill="{{ . }}"><path fill-rule="evenodd" d="M0 0h313.303v159.865H0z"/></mask><mask id="b" fill="{{ . }}"><path fill-rule="evenodd" d="M0 0h313.303v159.865H0z"/></mask><g fill="none" fill-rule="evenodd"><path fill="{{ . }}" d="M.679 138h19.785v26.789h23.904V138h19.786v75.25H44.368v-28.695H20.464v28.695H.68zm86.173 75.25V138h46.803v16.354h-27.017v12.241h23.904v16.655h-23.904v13.846h27.017v16.154zm68.498 0V138h19.785v55.384h27.118v19.866zM232.886 138l30.733 27.893L294.252 138h8.939v75.25h-19.886v-38.628l-19.686 17.96-19.786-17.86v38.528h-19.886V138z"/><g fill="{{ . }}" mask="url(#a)" transform="matrix(1 0 0 -1 .958 404)"><path d="M223.651 143.376c5.682 3.979 18.782-4.927 29.26-19.891s14.367-30.32 8.685-34.3c-5.682-3.978-18.782 4.928-29.26 19.892s-14.367 30.32-8.685 34.3zM88.278 143.376c-5.682 3.979-18.783-4.927-29.26-19.891s-14.367-30.32-8.685-34.3 18.782 4.928 29.26 19.892 14.366 30.32 8.685 34.3zM155.896 119.946c-6.937 0-12.56-14.81-12.56-33.077 0-18.268 5.623-33.078 12.56-33.078 6.936 0 12.559 14.81 12.559 33.078s-5.623 33.077-12.56 33.077z"/></g><path stroke="{{ . }}" stroke-width="20" d="M251.467 173.1c-20.23-33.61-56.89-56.068-98.756-56.068-40.72 0-76.516 21.246-97.058 53.335m2.198 129.17c20.84 30.232 55.556 50.026 94.86 50.026 39.376 0 74.147-19.866 94.974-50.192" mask="url(#a)" transform="matrix(1 0 0 -1 .958 404)"/><g><g fill="{{ . }}" mask="url(#b)" transform="translate(.958 -51)"><path d="M223.651 140.917c5.682 3.978 18.782-4.927 29.26-19.892s14.367-30.32 8.685-34.299c-5.682-3.978-18.782 4.927-29.26 19.892s-14.367 30.32-8.685 34.299zM88.278 140.917c-5.682 3.978-18.783-4.927-29.26-19.892s-14.367-30.32-8.685-34.299 18.782 4.927 29.26 19.892 14.366 30.32 8.685 34.299zM155.896 117.487c-6.937 0-12.56-14.81-12.56-33.078s5.623-33.077 12.56-33.077c6.936 0 12.559 14.81 12.559 33.077 0 18.268-5.623 33.078-12.56 33.078z"/></g><path stroke="{{ . }}" stroke-width="20" d="M251.467 170.64c-20.23-33.61-56.89-56.068-98.756-56.068-40.72 0-76.516 21.246-97.058 53.335m2.198 129.17c20.84 30.232 55.556 50.026 94.86 50.026 39.376 0 74.147-19.866 94.974-50.191" mask="url(#b)" transform="translate(.958 -51)"/></g></g></svg>
{{ end }}

{{ define "svg-docker" }}
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 122.88 88.17"><path fill="{{ . }}" d="M121.68 33.34c-.34-.28-3.42-2.62-10.03-2.62-1.71 0-3.48.17-5.19.46-1.25-8.72-8.49-12.94-8.78-13.16l-1.77-1.03-1.14 1.65a24.3 24.3 0 00-3.13 7.29c-1.2 4.96-.46 9.63 2.05 13.62-3.02 1.71-7.92 2.11-8.95 2.17H3.81a3.82 3.82 0 00-3.82 3.82 57.752 57.752 0 003.53 20.8c2.79 7.29 6.95 12.71 12.31 16.01 6.04 3.7 15.9 5.81 27.01 5.81 5.01 0 10.03-.46 14.99-1.37 6.9-1.25 13.51-3.65 19.6-7.12a53.72 53.72 0 0013.34-10.94c6.44-7.24 10.26-15.33 13.05-22.51h1.14c7.01 0 11.34-2.79 13.73-5.19 1.6-1.48 2.79-3.31 3.65-5.36l.51-1.48-1.17-.85zm-50.09 6.04h10.83c.51 0 .97-.4.97-.97v-9.69c0-.51-.4-.97-.97-.97H71.59c-.51 0-.97.4-.97.97v9.69c.06.57.46.97.97.97zm-15.1-27.75h10.83c.51 0 .97-.4.97-.97V.97c0-.51-.46-.97-.97-.97H56.49c-.51 0-.97.4-.97.97v9.69c0 .51.45.97.97.97zm0 13.9h10.83c.51 0 .97-.46.97-.97v-9.69c0-.51-.46-.97-.97-.97H56.49c-.51 0-.97.4-.97.97v9.69c0 .52.45.97.97.97zm-14.99 0h10.83c.51 0 .97-.46.97-.97v-9.69c0-.51-.4-.97-.97-.97H41.5c-.51 0-.97.4-.97.97v9.69c0 .52.4.97.97.97zm-15.22 0h10.83c.51 0 .97-.46.97-.97v-9.69c0-.51-.4-.97-.97-.97H26.28c-.51 0-.97.4-.97.97v9.69c.06.52.46.97.97.97zm30.21 13.85h10.83c.51 0 .97-.4.97-.97v-9.69c0-.51-.4-.97-.97-.97H56.49c-.51 0-.97.4-.97.97v9.69c0 .57.45.97.97.97zm-14.99 0h10.83c.51 0 .97-.4.97-.97v-9.69c0-.51-.4-.97-.97-.97H41.5c-.51 0-.97.4-.97.97v9.69c0 .57.4.97.97.97zm-15.22 0h10.83c.51 0 .97-.4.97-.97v-9.69c0-.51-.4-.97-.97-.97H26.28c-.51 0-.97.4-.97.97v9.69c.06.57.46.97.97.97zm-14.93 0h10.83c.51 0 .97-.4.97-.97v-9.69c0-.51-.4-.97-.97-.97H11.35c-.51 0-.97.4-.97.97v9.69c.06.57.46.97.97.97z"/></svg>
{{ end }}

{{ define "svg-question" }}
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><defs/><path fill="{{ . }}" d="M504 256c0 136.997-111.043 248-248 248S8 392.997 8 256C8 119.083 119.043 8 256 8s248 111.083 248 248zM262.655 90c-54.497 0-89.255 22.957-116.549 63.758-3.536 5.286-2.353 12.415 2.715 16.258l34.699 26.31c5.205 3.947 12.621 3.008 16.665-2.122 17.864-22.658 30.113-35.797 57.303-35.797 20.429 0 45.698 13.148 45.698 32.958 0 14.976-12.363 22.667-32.534 33.976C247.128 238.528 216 254.941 216 296v4c0 6.627 5.373 12 12 12h56c6.627 0 12-5.373 12-12v-1.333c0-28.462 83.186-29.647 83.186-106.667 0-58.002-60.165-102-116.531-102zM256 338c-25.365 0-46 20.635-46 46 0 25.364 20.635 46 46 46s46-20.636 46-46c0-25.365-20.635-46-46-46z"/></svg>
Expand Down
3 changes: 3 additions & 0 deletions pkg/ketchup/ketchups.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,11 @@ func (a app) handleCreate(w http.ResponseWriter, r *http.Request) {
repository = model.NewGithubRepository(0, name)
case model.Helm:
repository = model.NewHelmRepository(0, strings.TrimSuffix(name, "/"), r.FormValue("part"))
case model.Docker:
repository = model.NewDockerRepository(0, name)
default:
a.rendererApp.Error(w, httpModel.WrapInternal(fmt.Errorf("unhandled repository kind `%s`", repositoryKind)))
return
}

item := model.NewKetchup(r.FormValue("pattern"), r.FormValue("version"), ketchupFrequency, repository)
Expand Down
1 change: 1 addition & 0 deletions pkg/ketchup/signup.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ func (a app) Signup() http.Handler {
token := r.FormValue("token")
if !a.validateToken(r.Context(), token, r.FormValue("answer")) {
a.rendererApp.Error(w, httpModel.WrapInvalid(errors.New("unable to validate security question")))
return
}

user := model.NewUser(0, r.FormValue("email"), authModel.User{
Expand Down
7 changes: 6 additions & 1 deletion pkg/model/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const (

var (
// RepositoryKindValues string values
RepositoryKindValues = []string{"github", "helm"}
RepositoryKindValues = []string{"github", "helm", "docker"}

// NoneRepository is an undefined repository
NoneRepository = Repository{}
Expand Down Expand Up @@ -77,6 +77,11 @@ func NewHelmRepository(id uint64, name, part string) Repository {
return NewRepository(id, Helm, name, part)
}

// NewDockerRepository create new Repository with initialized values
func NewDockerRepository(id uint64, name string) Repository {
return NewRepository(id, Docker, name, "")
}

// AddVersion adds given pattern to versions map
func (r Repository) AddVersion(pattern, version string) Repository {
r.Versions[pattern] = version
Expand Down
4 changes: 2 additions & 2 deletions sql/ddl.sql
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ CREATE UNIQUE INDEX user_login_id ON ketchup.user(login_id);
CREATE UNIQUE INDEX user_email ON ketchup.user(email);

-- repository_kind
CREATE TYPE ketchup.repository_kind AS ENUM ('github', 'helm');
CREATE TYPE ketchup.repository_kind AS ENUM ('github', 'helm', 'docker');

-- repository
CREATE SEQUENCE ketchup.repository_seq;
Expand All @@ -49,7 +49,7 @@ CREATE TABLE ketchup.repository (
ALTER SEQUENCE ketchup.repository_seq OWNED BY ketchup.repository.id;

CREATE UNIQUE INDEX repository_id ON ketchup.repository(id);
CREATE UNIQUE INDEX repository_repository ON ketchup.repository(name, part);
CREATE UNIQUE INDEX repository_repository ON ketchup.repository(kind, name, part);

-- repository_version
CREATE TABLE ketchup.repository_version (
Expand Down
4 changes: 4 additions & 0 deletions sql/migration_2021-05-22_1.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
ALTER TYPE ketchup.repository_kind ADD VALUE 'docker';

DROP INDEX repository_repository;
CREATE UNIQUE INDEX repository_repository ON ketchup.repository(kind, name, part);

0 comments on commit de79d66

Please sign in to comment.