Skip to content
This repository has been archived by the owner on Mar 28, 2023. It is now read-only.

Commit

Permalink
Merge pull request #339 from OpenBazaar/TS_docker
Browse files Browse the repository at this point in the history
Ts docker
  • Loading branch information
cpacia authored Jan 25, 2017
2 parents 9607988 + 5ae61d4 commit 5b50d26
Show file tree
Hide file tree
Showing 15 changed files with 717 additions and 13 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ _testmain.go
.idea/
*.iml
.gx/
dist

# Development environment files
.ackrc
Expand Down
14 changes: 14 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
FROM ubuntu
MAINTAINER OpenBazaar Developers

RUN apt-get update && apt-get install -y ca-certificates

EXPOSE 4001
EXPOSE 4002
EXPOSE 8080

VOLUME /var/openbazaar

COPY ./dist/openbazaar-go-linux-amd64 /opt/openbazaard

CMD ["/opt/openbazaard", "start", "-t", "-d", "/var/openbazaar"]
38 changes: 38 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
##
## Building
##

deploy:
./deploy.sh

build:
./build.sh

build_linux:
./build.sh linux/amd64

##
## docker
##
DOCKER_PROFILE ?= openbazaar
DOCKER_IMAGE_NAME ?= $(DOCKER_PROFILE)/openbazaard

build_docker:
docker build -t $(DOCKER_IMAGE_NAME) .

push_docker:
docker push $(DOCKER_IMAGE_NAME)

docker: build_linux build_docker push_docker

##
## Cleanup
##

clean_build:
rm -f ./dist/*

clean_docker:
docker rmi -f $(DOCKER_IMAGE_NAME); true

clean: clean_build clean_docker
10 changes: 10 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/bash

TARGETS=${1:-windows/386,windows/amd64,darwin/amd64,linux/386,linux/amd64,linux/arm}

export CGO_ENABLED=1
docker pull karalabe/xgo-latest
go get github.com/karalabe/xgo
mkdir dist
(cd dist/ && xgo --targets=$TARGETS ../)
(chmod +x ./dist/*)
5 changes: 5 additions & 0 deletions core/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ import (
"time"
)

var (
VERSION = "0.4.3"
USERAGENT = "/openbazaar-go:" + VERSION + "/"
)

var log = logging.MustGetLogger("core")

var Node *OpenBazaarNode
Expand Down
7 changes: 1 addition & 6 deletions deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,7 @@ if [ ! -z "$TRAVIS_TAG" ] &&
echo "This will deploy!"

# Cross-compile for all platforms
export CGO_ENABLED=1
docker pull karalabe/xgo-latest
go get github.com/karalabe/xgo
mkdir dist/ && cd dist/
xgo --targets=windows/386,windows/amd64,darwin/amd64,linux/386,linux/amd64,linux/arm ../
chmod +x *
./build.sh

# Copy libwinpthread-1.dll (user must rename the dll for their system to libwinpthread-1.dll)
cp ../.travis/win32/libwinpthread-1.dll dist/libwinpthread-1.win32.dll
Expand Down
13 changes: 13 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
version: '2'

services:
openbazaard:
build: .
ports:
- 4001
- 4002
volumes:
- obdata:/var/openbazaar

volumes:
obdata:
7 changes: 7 additions & 0 deletions dummy/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
FROM openbazaar/openbazaard:latest
MAINTAINER OpenBazaar Developers

COPY ./run.sh /opt/run.sh
COPY ./dist/dummy-linux-amd64 /opt/dummy

CMD ["/opt/run.sh"]
37 changes: 37 additions & 0 deletions dummy/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
##
## Building
##

build: build_linux build_docker_image
build_linux:
docker pull karalabe/xgo-latest
go get github.com/karalabe/xgo
mkdir dist; true
(cd dist && xgo --targets=linux/amd64 ../)
(chmod +x ./dist/*)

##
## docker
##
DOCKER_PROFILE ?= openbazaar
DOCKER_IMAGE_NAME ?= $(DOCKER_PROFILE)/openbazaard_dummy

build_docker:
docker build -t $(DOCKER_IMAGE_NAME) .

push_docker:
docker push $(DOCKER_IMAGE_NAME)

docker: build_linux build_docker push_docker

##
## Cleanup
##

clean_build:
rm -f ./dist/*

clean_docker:
docker rmi -f $(DOCKER_IMAGE_NAME); true

clean: clean_build clean_docker
140 changes: 140 additions & 0 deletions dummy/listing.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
package main

import (
"math/rand"
"strconv"

"github.com/OpenBazaar/openbazaar-go/pb"
"github.com/golang/protobuf/ptypes/timestamp"
"github.com/icrowley/fake"
)

var conditions = []string{"New", "Used", "Bad", "Most Excellent"}

var categories = []string{
"Arts",
"Electronics",
"Entertainment",
"Home",
"Food",
"Personal",
"Services",
"Digital Goods",
"Other",
}

func newRandomListing() *pb.ListingReqApi {
title := fake.ProductName()
slug := slugify(title)
sku := slug + "-" + fake.Digits()

tags := make([]string, rand.Intn(9)+1)
tags[0] = fake.Word()
for i := 1; i < len(tags); i++ {
tags[i] = fake.Word()
}

// Create a random amount of options with random amounts of varients
options := make([]*pb.Listing_Item_Option, rand.Intn(4)+2)
for i := 0; i < len(options); i++ {
options[i] = &pb.Listing_Item_Option{
Name: fake.ProductName(),
Description: fake.Sentence(),
Variants: make([]*pb.Listing_Item_Option_Variants, rand.Intn(2)+2),
}

// Ensure description is <= 70
if len(options[i].Description) > 70 {
options[i].Description = options[i].Description[:70]
}

for j := 0; j < len(options[i].Variants); j++ {
options[i].Variants[j] = &pb.Listing_Item_Option_Variants{
Name: title + " " + fake.ProductName(),
Image: &pb.Listing_Item_Image{
Filename: "example.jpg",
Original: "QmdfiTnhj1oqiCDmhxu1gdgW6ZqtR7D6ZE7j7CqWUHgKJ8",
Tiny: "QmbKPEBbzVwax8rnrdxLepfmNkdTqnw2RSfJE19iax3fLK",
Small: "QmQ77aAsYjs1rxcp7xZ5qUki1RGDGjQ99cok3ynUMF8Sc5",
Medium: "QmVoh493xbSaKYV9yLtEapaGQ7J31gdCiDQHGSd86PNo8B",
Large: "QmUWuTZhjUuY8VYWVZrcodsrsbQvckSZwTRxmJ3Avhnw1y",
},
PriceModifier: int64(rand.Intn(50)),
}

// Ensure name is <= 40 chars
if len(options[i].Variants[j].Name) > 40 {
options[i].Variants[j].Name = options[i].Variants[j].Name[:40]
}
}
}

countries := make([]pb.CountryCode, rand.Intn(254)+1)
for i := 0; i < len(countries); i++ {
countries[i] = pb.CountryCode(rand.Intn(255))
}

return &pb.ListingReqApi{
Listing: &pb.Listing{
Slug: slug,
Metadata: &pb.Listing_Metadata{
Version: 1,
AcceptedCurrency: "btc",
PricingCurrency: "btc",
Expiry: &timestamp.Timestamp{Seconds: 2147483647},
Format: pb.Listing_Metadata_FIXED_PRICE,
ContractType: pb.Listing_Metadata_ContractType(uint32(rand.Intn(3))),
},
Item: &pb.Listing_Item{
Sku: sku,
Title: title,
Tags: tags,
Options: options,
Nsfw: isNSFW(),
Description: fake.Paragraphs(),
Price: uint64(rand.Intn(9999)),
ProcessingTime: strconv.Itoa(rand.Intn(14)+1) + " days",
Categories: []string{categories[rand.Intn(len(categories))]},
Grams: float32(rand.Intn(5000)),
Condition: conditions[rand.Intn(len(conditions))],
Images: []*pb.Listing_Item_Image{
{
Filename: "example.jpg",
Original: "QmdfiTnhj1oqiCDmhxu1gdgW6ZqtR7D6ZE7j7CqWUHgKJ8",
Tiny: "QmbKPEBbzVwax8rnrdxLepfmNkdTqnw2RSfJE19iax3fLK",
Small: "QmQ77aAsYjs1rxcp7xZ5qUki1RGDGjQ99cok3ynUMF8Sc5",
Medium: "QmVoh493xbSaKYV9yLtEapaGQ7J31gdCiDQHGSd86PNo8B",
Large: "QmUWuTZhjUuY8VYWVZrcodsrsbQvckSZwTRxmJ3Avhnw1y",
},
},
},
ShippingOptions: []*pb.Listing_ShippingOption{
{
Name: "usps",
Type: pb.Listing_ShippingOption_FIXED_PRICE,
Regions: countries,
Services: []*pb.Listing_ShippingOption_Service{
{
Name: "standard",
Price: uint64(rand.Intn(999)),
EstimatedDelivery: fake.Digits() + " days",
},
},
ShippingRules: &pb.Listing_ShippingOption_ShippingRules{
RuleType: pb.Listing_ShippingOption_ShippingRules_FLAT_FEE_QUANTITY_RANGE,
Rules: []*pb.Listing_ShippingOption_ShippingRules_Rule{
{
MinRange: 0,
MaxRange: 99999999,
Price: uint64(rand.Intn(999)),
},
},
},
},
},

TermsAndConditions: fake.Sentences(),
RefundPolicy: fake.Sentence(),
},
}
}
Loading

0 comments on commit 5b50d26

Please sign in to comment.