Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions .env.dev_docker
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
APT_ENV="dev_docker"
DB_DRIVER="postgres"
DB_HOST="postgres_docker_local"
DB_NAME="apt_registry_development"
DB_USER="dev_user"
DB_PASSWORD="password"
DB_PORT=5432
DB_USE_SSL=false
COOKIE_HASH_KEY='y0b6|UBJQ(N$KB)jAJYL-aj=:q?;yK64^TPch0=|1XNnv{X@QrL#?80u$1]LcBF'
COOKIE_BLOCK_KEY='4Qdnm4acxfAILGEFQ3jUj0PoLbMWbyMm'
COOKIE_DOMAIN="localhost"
SESSION_MAX_AGE=43200
SESSION_COOKIE_NAME="aptrust_session"
FLASH_COOKIE_NAME="aptrust_flash"
PREFS_COOKIE_NAME="aptrust_prefs"
HTTPS_COOKIES=false
NSQ_URL='http://localhost:4151'
BATCH_DELETION_KEY="00000000-0000-0000-0000-000000000000"
EMAIL_SERVICE_TYPE="SMTP"
MAINTENANCE_MODE=false
ENABLE_TWO_FACTOR_SMS=false
SNS_ENDPOINT=""
AWS_SNS_USER=""
AWS_SNS_PWD=""
ENABLE_TWO_FACTOR_AUTHY=false
OTP_EXPIRATION="15m"
EMAIL_ENABLED=false
EMAIL_FROM_ADDRESS="help@aptrust.org"
REDIS_DEFAULT_DB=0
REDIS_PASSWORD=""
REDIS_URL="localhost:6379"
RETENTION_MINIMUM_GLACIER=90
RETENTION_MINIMUM_GLACIER_DEEP=180
RETENTION_MINIMUM_WASABI=90
RETENTION_MINIMUM_STANDARD=0
LOG_FILE="~/tmp/logs/registry_dev.log"
LOG_LEVEL=0
LOG_CALLER=false
LOG_TO_CONSOLE=true
LOG_SQL=false
40 changes: 40 additions & 0 deletions .env.local
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
DOCKER_ENV="dev_docker"
DB_DRIVER="postgres"
DB_HOST="postgres_docker_local"
DB_NAME="apt_registry_development"
DB_USER="dev_user"
DB_PASSWORD="password"
DB_PORT=5432
DB_USE_SSL=false
COOKIE_HASH_KEY='y0b6|UBJQ(N$KB)jAJYL-aj=:q?;yK64^TPch0=|1XNnv{X@QrL#?80u$1]LcBF'
COOKIE_BLOCK_KEY='4Qdnm4acxfAILGEFQ3jUj0PoLbMWbyMm'
COOKIE_DOMAIN="localhost"
SESSION_MAX_AGE=43200
SESSION_COOKIE_NAME="aptrust_session"
FLASH_COOKIE_NAME="aptrust_flash"
PREFS_COOKIE_NAME="aptrust_prefs"
HTTPS_COOKIES=false
NSQ_URL='http://localhost:4151'
BATCH_DELETION_KEY="00000000-0000-0000-0000-000000000000"
EMAIL_SERVICE_TYPE="SMTP"
MAINTENANCE_MODE=false
ENABLE_TWO_FACTOR_SMS=false
SNS_ENDPOINT=""
AWS_SNS_USER=""
AWS_SNS_PWD=""
ENABLE_TWO_FACTOR_AUTHY=false
OTP_EXPIRATION="15m"
EMAIL_ENABLED=false
EMAIL_FROM_ADDRESS="help@aptrust.org"
REDIS_DEFAULT_DB= 0
REDIS_PASSWORD=""
REDIS_URL="localhost:6379"
RETENTION_MINIMUM_GLACIER=90
RETENTION_MINIMUM_GLACIER_DEEP=180
RETENTION_MINIMUM_WASABI=90
RETENTION_MINIMUM_STANDARD=0
LOG_FILE="~/tmp/logs/registry_dev.log"
LOG_LEVEL=0
LOG_CALLER=false
LOG_TO_CONSOLE=true
LOG_SQL=false
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,6 @@ node_modules/

# Temp data used for seeing empty staging db
db/seed

# Ignore shared directory
shared
16 changes: 11 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
# syntax=docker/dockerfile:1

FROM golang:1.17.8-alpine
FROM golang:1.22.10-alpine3.20

RUN apk update && \
apk add --no-cache upx make build-base bash git
RUN echo "http://dl-cdn.alpinelinux.org/alpine/edge/community" >> /etc/apk/repositories && \
apk update && \
apk add --no-cache upx make build-base bash git redis

ENV CGO_ENABLED=0 \
GOOS=linux \
GOARCH=amd64
GOOS=linux \
GOARCH=amd64

WORKDIR /app

Expand All @@ -17,6 +18,11 @@ RUN go mod download

COPY . .

COPY db/schema.sql /docker-entrypoint-initdb.d/
COPY db/migrations/*.sql /docker-entrypoint-initdb.d/migrations/

RUN apk add --no-cache postgresql-client

RUN go build -o /main

#Environment VARS for deployment
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
[![Build Status](https://travis-ci.com/APTrust/registry.svg?branch=master)](https://travis-ci.com/APTrust/registry)
[![Maintainability](https://api.codeclimate.com/v1/badges/e4c7cfd351d6bae759e3/maintainability)](https://codeclimate.com/github/APTrust/registry/maintainability)
[![REST API Documentation](https://img.shields.io/badge/documentation-REST%20API-blue)](https://aptrust.github.io/registry/)

<!---
Test coverage report is incorrect because Travis blows up and reports incorrect numbers.
Actual coverage is around 80%. We can uncomment this when we move away from Travis.
Expand Down Expand Up @@ -133,7 +134,7 @@ Note that Go does not rerun tests that passed on the prior run. If you want to f

This may be necessary if the tests passed on the prior run, but you want to force a reload of the schema or the fixtures.

__Note__ Anytime you make substial updates to Registry (anything more than cosmetic UI changes), and anytime you update Registry's dependencies (e.g. when Dependabot tells you to upgrade an underlying library), you should all of the following tests to be sure there are no regressions:
**Note** Anytime you make substial updates to Registry (anything more than cosmetic UI changes), and anytime you update Registry's dependencies (e.g. when Dependabot tells you to upgrade an underlying library), you should all of the following tests to be sure there are no regressions:

`registry test` from Registry and

Expand Down
1 change: 1 addition & 0 deletions common/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
var allowedConfigs = []string{
"ci",
"dev",
"dev_docker",
"docker",
"integration",
"production",
Expand Down
14 changes: 7 additions & 7 deletions db/testutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package db

import (
"fmt"
"io/ioutil"
"os"
"path"
"path/filepath"
Expand All @@ -23,6 +22,7 @@ var SafeEnvironments = []string{
"integration",
"test",
"travis",
"dev_docker",
}

// LoadOrder lists the names of tables for which we have fixture data
Expand Down Expand Up @@ -184,7 +184,7 @@ func loadSchema(db *pg.DB) error {
file := filepath.Join("db", "schema.sql")
ddl, err := common.LoadRelativeFile(file)
if err != nil {
return fmt.Errorf("File %s: %v", file, err)
return fmt.Errorf("file %s: %v", file, err)
}
return runTransaction(db, string(ddl))
}
Expand All @@ -200,9 +200,9 @@ func runMigrations(db *pg.DB) error {
file := info.Name()
if info.Mode().IsRegular() && strings.HasSuffix(file, ".sql") {
absPath := filepath.Join(dir, file)
ddl, err := ioutil.ReadFile(absPath)
ddl, err := os.ReadFile(absPath)
if err != nil {
return fmt.Errorf("File %s: %v", file, err)
return fmt.Errorf("file %s: %v", file, err)
}
err = runTransaction(db, string(ddl))
if err != nil {
Expand Down Expand Up @@ -234,7 +234,7 @@ func loadCSVFile(db *pg.DB, table string) error {

// On Travis, posgres user can't read from Travis' home dir,
// so we have to copy our csv file to a readable temp dir.
if ctx.Config.EnvName == "travis" {
if ctx.Config.EnvName == "travis" || ctx.Config.EnvName == "dev_docker" {
tmpFile := path.Join(os.TempDir(), table+".csv")
err := common.CopyFile(file, tmpFile, 0666)
if err != nil {
Expand All @@ -247,7 +247,7 @@ func loadCSVFile(db *pg.DB, table string) error {
sql := fmt.Sprintf(`copy "%s" from '%s' csv header`, table, file)
err := runTransaction(db, sql)
if err != nil {
err = fmt.Errorf(`Error executing "%s": %v`, sql, err)
err = fmt.Errorf(`error executing "%s": %v`, sql, err)
}
return err
}
Expand Down Expand Up @@ -347,7 +347,7 @@ func panicOnWrongEnv() {
//
// Don't like the kludgy, ugly code below? See how much you
// like restoring 250GB of deleted data.
if ctx.Config.DB.Host != "localhost" {
if ctx.Config.DB.Host != "localhost" && ctx.Config.DB.Host != "postgres_docker_local" {
panic("Cannot run destructive DB operations against external servers.")
}
if !strings.HasSuffix(ctx.Config.DB.Name, "_development") &&
Expand Down
51 changes: 51 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
services:
postgres:
image: postgres:alpine
container_name: postgres
environment:
POSTGRES_USER: dev_user
POSTGRES_PASSWORD: password
POSTGRES_DB: apt_registry_development
volumes:
- ./shared/postgres_data:/var/lib/postgresql/data
- ./shared:/app/shared
# - ./init.sql:/docker-entrypoint-initdb.d/init.sql
networks:
app_network:
aliases:
- postgres_docker_local
ports:
- "5432:5432"

registry:
build:
context: .
dockerfile: Dockerfile
container_name: registry_app
depends_on:
- postgres
volumes:
- ./bin/linux:/app/bin/linux
- ./shared:/app/shared
- ./entrypoint.sh:/entrypoint.sh
- ./.env.dev_docker:/app/.env
- ./db/fixtures:/app/db/fixtures
environment:
- APT_ENV=dev_docker
- DB_DRIVER=postgres
- DB_HOST=postgres_docker_local
- DB_NAME=apt_registry_development
- DB_USER=dev_user
- DB_PASSWORD=password
- DB_PORT=5432
entrypoint: ["/bin/sh", "/entrypoint.sh"]
# command: sh -c "sleep 20 && APT_ENV=test ./registry test ; APT_ENV=dev ./registry start"
command: sh -c 'echo "Changing directory to /app" && cd /app && echo "Setting APT_ENV to dev_docker" && APT_ENV=dev_docker && echo "Running registry serve" && ./registry serve'
networks:
- app_network
ports:
- "8080:8080"

networks:
app_network:
driver: bridge
25 changes: 25 additions & 0 deletions entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/bin/sh
# Copy all executables from ./bin to /usr/local/bin
# cp ./bin/linux/nsqadmin /usr/local/bin/
# cp ./bin/linux/nsqd /usr/local/bin/
# cp ./bin/linux/nsqlookupd /usr/local/bin/
# cp ./bin/linux/redis-cli /usr/local/bin/
# cp ./bin/linux/redis-server /usr/local/bin/

# Wait for Postgres to be ready
until PGPASSWORD=$DB_PASSWORD pg_isready -h $DB_HOST -p $DB_PORT -U $DB_USER; do
echo "Waiting for Postgres..."
sleep 2
done

# Run schema and migration files
echo "Running schema.sql"
PGPASSWORD=$DB_PASSWORD psql -h $DB_HOST -p $DB_PORT -U $DB_USER -d $DB_NAME -f /docker-entrypoint-initdb.d/schema.sql
for file in /docker-entrypoint-initdb.d/migrations/*.sql; do
echo "Running migration $file"
PGPASSWORD=$DB_PASSWORD psql -h $DB_HOST -p $DB_PORT -U $DB_USER -d $DB_NAME -f "$file"
done

# Execute the original command
exec "$@"

3 changes: 3 additions & 0 deletions init.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
CREATE USER dev_user WITH PASSWORD 'password';
CREATE DATABASE apt_registry_development OWNER dev_user;
grant pg_read_server_files to dev_user;
Loading
Loading