Skip to content

Commit

Permalink
More Metadata for Catalog/Releases
Browse files Browse the repository at this point in the history
  • Loading branch information
richmahn committed Jul 10, 2022
1 parent 55ce2f4 commit 193b9e6
Show file tree
Hide file tree
Showing 28 changed files with 619 additions and 85 deletions.
5 changes: 5 additions & 0 deletions .dockerignore
@@ -0,0 +1,5 @@
.git
**/node_modules
mysql
data
data-*
24 changes: 12 additions & 12 deletions .drone.yml
Expand Up @@ -108,18 +108,18 @@ steps:
- make frontend
depends_on: [test-frontend]

- name: build-backend-no-gcc
image: golang:1.17 # this step is kept as the lowest version of golang that we support
pull: always
environment:
GO111MODULE: on
GOPROXY: https://goproxy.io
commands:
- go build -o gitea_no_gcc # test if build succeeds without the sqlite tag
depends_on: [deps-backend, checks-backend]
volumes:
- name: deps
path: /go
# - name: build-backend-no-gcc
# image: golang:1.17 # this step is kept as the lowest version of golang that we support
# pull: always
# environment:
# GO111MODULE: on
# GOPROXY: https://goproxy.io
# commands:
# - go build -o gitea_no_gcc # test if build succeeds without the sqlite tag
# depends_on: [deps-backend, checks-backend]
# volumes:
# - name: deps
# path: /go

- name: build-backend-arm64
image: golang:1.18
Expand Down
55 changes: 55 additions & 0 deletions Dockerfile-dev
@@ -0,0 +1,55 @@
#Build stage
FROM golang:1.18-alpine3.16

ARG GOPROXY
ENV GOPROXY ${GOPROXY:-direct}

ARG GITEA_VERSION
ARG TAGS="sqlite sqlite_unlock_notify sqlite_json"
ENV TAGS "bindata timetzdata $TAGS"
ARG CGO_EXTRA_CFLAGS

#Setup repo
COPY . ${GOPATH}/src/code.gitea.io/gitea
WORKDIR ${GOPATH}/src/code.gitea.io/gitea

EXPOSE 22 3000 80

RUN apk --no-cache add \
bash \
ca-certificates \
curl \
gettext \
linux-pam \
openssh \
s6 \
sqlite \
su-exec \
gnupg \
make \
build-base \
git \
nodejs \
npm \
build-base

RUN apk add git --repository=http://dl-cdn.alpinelinux.org/alpine/v3.16/main

RUN addgroup \
-S -g 1000 \
git && \
adduser \
-S -H -D \
-h /data/git \
-s /bin/bash \
-u 1000 \
-G git \
git && \
echo "git:*" | chpasswd -e

ENV USER git
ENV GITEA_CUSTOM /data/gitea

VOLUME ["/data"]

CMD sh -c 'ln -s /go/src/code.gitea.io /app'; tail -f /data/gitea/log/gitea.log
52 changes: 52 additions & 0 deletions docker-compose.develop.yml
@@ -0,0 +1,52 @@
version: "3"

services:
dcs:
container_name: dcs
image: dcs-dev:latest
build:
context: .
dockerfile: Dockerfile-dev
user: "${UID}:${GID}"
environment:
- USER_UID="${UID}"
- USER_GID="${GID}"
- GITEA__database__DB_TYPE=mysql
- GITEA__database__HOST=db:3306
- GITEA__database__NAME=gitea-release
- GITEA__database__USER=gitea
- GITEA__database__PASSWD=gitea
- TAGS=bindata sqlite sqlite_unlock_notify sqlite_json
restart: always
networks:
- gitea
volumes:
- /etc/timezone:/etc/timezone:ro
- /etc/localtime:/etc/localtime:ro
- ./data-release:/data
- .:/go/src/code.gitea.io/gitea
ports:
- "${DCS_PORT-3000}:80"
- "222:22"
depends_on:
- db
stdin_open: true # docker run -i
tty: true # docker run -t

db:
platform: linux/x86_64
image: mysql:5.7
restart: always
environment:
- MYSQL_ROOT_PASSWORD=gitea
- MYSQL_USER=gitea
- MYSQL_PASSWORD=gitea
- MYSQL_DATABASE=gitea-release
networks:
- gitea
volumes:
- ./mysql:/var/lib/mysql

networks:
gitea:
external: false
3 changes: 2 additions & 1 deletion docker-compose.main.yml
Expand Up @@ -2,6 +2,7 @@ version: "3"

services:
dcs:
container_name: dcs
build: .
environment:
- USER_UID=1000
Expand All @@ -19,7 +20,7 @@ services:
- /etc/localtime:/etc/localtime:ro
- ./data-main:/data
ports:
- "${DCS_PORT-3000}:3000"
- "${DCS_PORT-3000}:80"
- "222:22"
depends_on:
- db
Expand Down
5 changes: 3 additions & 2 deletions docker-compose.release.yml
Expand Up @@ -2,6 +2,7 @@ version: "3"

services:
dcs:
container_name: dcs
build: .
image: dcs-local:release
environment:
Expand All @@ -14,13 +15,13 @@ services:
- GITEA__database__PASSWD=gitea
restart: always
networks:
- gitea
- gitea
volumes:
- /etc/timezone:/etc/timezone:ro
- /etc/localtime:/etc/localtime:ro
- ./data-release:/data
ports:
- "${DCS_PORT-3000}:3000"
- "${DCS_PORT-3000}:80"
- "222:22"
depends_on:
- db
Expand Down
8 changes: 6 additions & 2 deletions models/door43metadata.go
Expand Up @@ -75,7 +75,10 @@ func (dm *Door43Metadata) getRelease(e db.Engine) error {
return err
}
dm.Release.Repo = dm.Repo
return dm.Release.LoadAttributes()
if err := dm.Release.LoadAttributes(); err != nil {
log.Warn("loadAttributes Error: %v\n", err)
return err
}
}
return nil
}
Expand All @@ -86,6 +89,7 @@ func (dm *Door43Metadata) loadAttributes(e db.Engine) error {
}
if dm.Release == nil && dm.ReleaseID > 0 {
if err := dm.getRelease(e); err != nil {
log.Error("getRelease: %v", err)
return nil
}
}
Expand Down Expand Up @@ -188,7 +192,7 @@ func (dm *Door43Metadata) GetContentsURL() string {
return fmt.Sprintf("%s/contents?ref=%s", dm.Repo.APIURL(), dm.BranchOrTag)
}

// GetBooks get the books of the resource
// GetBooks get the books of the manifest
func (dm *Door43Metadata) GetBooks() []string {
var books []string
if len((*dm.Metadata)["projects"].([]interface{})) > 0 {
Expand Down
1 change: 0 additions & 1 deletion models/release.go
Expand Up @@ -152,7 +152,6 @@ func AddReleaseAttachments(ctx context.Context, releaseID int64, attachmentUUIDs
return fmt.Errorf("update attachment [%d]: %v", attachments[i].ID, err)
}
}

return
}

Expand Down
44 changes: 44 additions & 0 deletions models/repo/attachment.go
Expand Up @@ -9,6 +9,7 @@ import (
"fmt"
"net/url"
"path"
"strings" // DCS Customizations

"code.gitea.io/gitea/models/db"
"code.gitea.io/gitea/modules/setting"
Expand All @@ -29,12 +30,50 @@ type Attachment struct {
DownloadCount int64 `xorm:"DEFAULT 0"`
Size int64 `xorm:"DEFAULT 0"`
CreatedUnix timeutil.TimeStamp `xorm:"created"`
/*** DCS Customizations ***/
BrowserDownloadURL string `xorm:"-" json:"browser_download_url"`
/*** END DCS Customizations ***/
}

func init() {
db.RegisterModel(new(Attachment))
}

/*** DCS Customizations ***/

func (a *Attachment) AfterLoad() {
if strings.Contains(a.Name, "|http") || strings.Contains(a.Name, "|ftp") {
if name, url, ok := strings.Cut(a.Name, "|"); ok {
a.Name = name
a.BrowserDownloadURL = url
}
}
}

func (a *Attachment) BeforeInsert() {
if a.Name == "" && a.BrowserDownloadURL != "" {
u, _ := url.Parse(a.BrowserDownloadURL)
a.Name = path.Base(u.Path)
}
if a.BrowserDownloadURL != "" {
a.Name = fmt.Sprintf("%s|%s", a.Name, a.BrowserDownloadURL)
}
}

func (a *Attachment) BeforeUpdate() {
a.BeforeInsert()
}

func (a *Attachment) AfterInsert() {
a.AfterLoad()
}

func (a *Attachment) AfterUpdate() {
a.AfterLoad()
}

/*** END DCS Customiations ***/

// IncreaseDownloadCount is update download count + 1
func (a *Attachment) IncreaseDownloadCount() error {
// Update download count.
Expand All @@ -57,6 +96,11 @@ func (a *Attachment) RelativePath() string {

// DownloadURL returns the download url of the attached file
func (a *Attachment) DownloadURL() string {
/*** DCS Customizations ***/
if a.BrowserDownloadURL != "" {
return a.BrowserDownloadURL
}
/*** END DCS Customizations ***/
return setting.AppURL + "attachments/" + url.PathEscape(a.UUID)
}

Expand Down
14 changes: 14 additions & 0 deletions models/repo/repo.go
Expand Up @@ -252,6 +252,20 @@ func (repo *Repository) APIURL() string {
return setting.AppURL + "api/v1/repos/" + url.PathEscape(repo.OwnerName) + "/" + url.PathEscape(repo.Name)
}

/*** DCS Customizations ***/

// CatalogSearchURL returns the repository catalog search API URL
func (repo *Repository) CatalogSearchURL() string {
return setting.AppURL + "api/catalog/latest/search/" + url.PathEscape(repo.OwnerName) + "/" + url.PathEscape(repo.Name)
}

// CatalogEntryURL returns the repository catalog entry API URL
func (repo *Repository) CatalogEntryURL() string {
return setting.AppURL + "api/catalog/latest/entry/" + url.PathEscape(repo.OwnerName) + "/" + url.PathEscape(repo.Name)
}

/*** END DCS Customizations ***/

// GetCommitsCountCacheKey returns cache key used for commits count caching.
func (repo *Repository) GetCommitsCountCacheKey(contextName string, isRef bool) string {
var prefix string
Expand Down
6 changes: 3 additions & 3 deletions models/repo_list_test.go
Expand Up @@ -234,13 +234,13 @@ func TestSearchRepository(t *testing.T) {
{
name: "AllPublic/PublicRepositoriesOfUserIncludingCollaborative",
opts: &SearchRepoOptions{ListOptions: db.ListOptions{Page: 1, PageSize: 10}, OwnerID: 15, AllPublic: true, Template: util.OptionalBoolFalse},
/*** DCS Customization - Adds 1 more test, total 29 ***/
/*** DCS Customizations - Adds 1 more test, total 29 ***/
count: 29,
},
{
name: "AllPublic/PublicAndPrivateRepositoriesOfUserIncludingCollaborative",
opts: &SearchRepoOptions{ListOptions: db.ListOptions{Page: 1, PageSize: 10}, OwnerID: 15, Private: true, AllPublic: true, AllLimited: true, Template: util.OptionalBoolFalse},
/*** DCS Customization - Adds 1 more test, total 34 ***/
/*** DCS Customizations - Adds 1 more test, total 34 ***/
count: 34,
},
{
Expand All @@ -256,7 +256,7 @@ func TestSearchRepository(t *testing.T) {
{
name: "AllPublic/PublicRepositoriesOfOrganization",
opts: &SearchRepoOptions{ListOptions: db.ListOptions{Page: 1, PageSize: 10}, OwnerID: 17, AllPublic: true, Collaborate: util.OptionalBoolFalse, Template: util.OptionalBoolFalse},
/*** DCS Customization - Adds 1 more test, total 29 ***/
/*** DCS Customizations - Adds 1 more test, total 29 ***/
count: 29,
},
{
Expand Down

0 comments on commit 193b9e6

Please sign in to comment.