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

Commit 5b50d26

Browse files
authored
Merge pull request #339 from OpenBazaar/TS_docker
Ts docker
2 parents 9607988 + 5ae61d4 commit 5b50d26

15 files changed

+717
-13
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ _testmain.go
2626
.idea/
2727
*.iml
2828
.gx/
29+
dist
2930

3031
# Development environment files
3132
.ackrc

Dockerfile

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
FROM ubuntu
2+
MAINTAINER OpenBazaar Developers
3+
4+
RUN apt-get update && apt-get install -y ca-certificates
5+
6+
EXPOSE 4001
7+
EXPOSE 4002
8+
EXPOSE 8080
9+
10+
VOLUME /var/openbazaar
11+
12+
COPY ./dist/openbazaar-go-linux-amd64 /opt/openbazaard
13+
14+
CMD ["/opt/openbazaard", "start", "-t", "-d", "/var/openbazaar"]

Makefile

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
##
2+
## Building
3+
##
4+
5+
deploy:
6+
./deploy.sh
7+
8+
build:
9+
./build.sh
10+
11+
build_linux:
12+
./build.sh linux/amd64
13+
14+
##
15+
## docker
16+
##
17+
DOCKER_PROFILE ?= openbazaar
18+
DOCKER_IMAGE_NAME ?= $(DOCKER_PROFILE)/openbazaard
19+
20+
build_docker:
21+
docker build -t $(DOCKER_IMAGE_NAME) .
22+
23+
push_docker:
24+
docker push $(DOCKER_IMAGE_NAME)
25+
26+
docker: build_linux build_docker push_docker
27+
28+
##
29+
## Cleanup
30+
##
31+
32+
clean_build:
33+
rm -f ./dist/*
34+
35+
clean_docker:
36+
docker rmi -f $(DOCKER_IMAGE_NAME); true
37+
38+
clean: clean_build clean_docker

build.sh

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/bin/bash
2+
3+
TARGETS=${1:-windows/386,windows/amd64,darwin/amd64,linux/386,linux/amd64,linux/arm}
4+
5+
export CGO_ENABLED=1
6+
docker pull karalabe/xgo-latest
7+
go get github.com/karalabe/xgo
8+
mkdir dist
9+
(cd dist/ && xgo --targets=$TARGETS ../)
10+
(chmod +x ./dist/*)

core/core.go

+5
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@ import (
2424
"time"
2525
)
2626

27+
var (
28+
VERSION = "0.4.3"
29+
USERAGENT = "/openbazaar-go:" + VERSION + "/"
30+
)
31+
2732
var log = logging.MustGetLogger("core")
2833

2934
var Node *OpenBazaarNode

deploy.sh

+1-6
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,7 @@ if [ ! -z "$TRAVIS_TAG" ] &&
55
echo "This will deploy!"
66

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

1510
# Copy libwinpthread-1.dll (user must rename the dll for their system to libwinpthread-1.dll)
1611
cp ../.travis/win32/libwinpthread-1.dll dist/libwinpthread-1.win32.dll

docker-compose.yml

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
version: '2'
2+
3+
services:
4+
openbazaard:
5+
build: .
6+
ports:
7+
- 4001
8+
- 4002
9+
volumes:
10+
- obdata:/var/openbazaar
11+
12+
volumes:
13+
obdata:

dummy/Dockerfile

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
FROM openbazaar/openbazaard:latest
2+
MAINTAINER OpenBazaar Developers
3+
4+
COPY ./run.sh /opt/run.sh
5+
COPY ./dist/dummy-linux-amd64 /opt/dummy
6+
7+
CMD ["/opt/run.sh"]

dummy/Makefile

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
##
2+
## Building
3+
##
4+
5+
build: build_linux build_docker_image
6+
build_linux:
7+
docker pull karalabe/xgo-latest
8+
go get github.com/karalabe/xgo
9+
mkdir dist; true
10+
(cd dist && xgo --targets=linux/amd64 ../)
11+
(chmod +x ./dist/*)
12+
13+
##
14+
## docker
15+
##
16+
DOCKER_PROFILE ?= openbazaar
17+
DOCKER_IMAGE_NAME ?= $(DOCKER_PROFILE)/openbazaard_dummy
18+
19+
build_docker:
20+
docker build -t $(DOCKER_IMAGE_NAME) .
21+
22+
push_docker:
23+
docker push $(DOCKER_IMAGE_NAME)
24+
25+
docker: build_linux build_docker push_docker
26+
27+
##
28+
## Cleanup
29+
##
30+
31+
clean_build:
32+
rm -f ./dist/*
33+
34+
clean_docker:
35+
docker rmi -f $(DOCKER_IMAGE_NAME); true
36+
37+
clean: clean_build clean_docker

dummy/listing.go

+140
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
package main
2+
3+
import (
4+
"math/rand"
5+
"strconv"
6+
7+
"github.com/OpenBazaar/openbazaar-go/pb"
8+
"github.com/golang/protobuf/ptypes/timestamp"
9+
"github.com/icrowley/fake"
10+
)
11+
12+
var conditions = []string{"New", "Used", "Bad", "Most Excellent"}
13+
14+
var categories = []string{
15+
"Arts",
16+
"Electronics",
17+
"Entertainment",
18+
"Home",
19+
"Food",
20+
"Personal",
21+
"Services",
22+
"Digital Goods",
23+
"Other",
24+
}
25+
26+
func newRandomListing() *pb.ListingReqApi {
27+
title := fake.ProductName()
28+
slug := slugify(title)
29+
sku := slug + "-" + fake.Digits()
30+
31+
tags := make([]string, rand.Intn(9)+1)
32+
tags[0] = fake.Word()
33+
for i := 1; i < len(tags); i++ {
34+
tags[i] = fake.Word()
35+
}
36+
37+
// Create a random amount of options with random amounts of varients
38+
options := make([]*pb.Listing_Item_Option, rand.Intn(4)+2)
39+
for i := 0; i < len(options); i++ {
40+
options[i] = &pb.Listing_Item_Option{
41+
Name: fake.ProductName(),
42+
Description: fake.Sentence(),
43+
Variants: make([]*pb.Listing_Item_Option_Variants, rand.Intn(2)+2),
44+
}
45+
46+
// Ensure description is <= 70
47+
if len(options[i].Description) > 70 {
48+
options[i].Description = options[i].Description[:70]
49+
}
50+
51+
for j := 0; j < len(options[i].Variants); j++ {
52+
options[i].Variants[j] = &pb.Listing_Item_Option_Variants{
53+
Name: title + " " + fake.ProductName(),
54+
Image: &pb.Listing_Item_Image{
55+
Filename: "example.jpg",
56+
Original: "QmdfiTnhj1oqiCDmhxu1gdgW6ZqtR7D6ZE7j7CqWUHgKJ8",
57+
Tiny: "QmbKPEBbzVwax8rnrdxLepfmNkdTqnw2RSfJE19iax3fLK",
58+
Small: "QmQ77aAsYjs1rxcp7xZ5qUki1RGDGjQ99cok3ynUMF8Sc5",
59+
Medium: "QmVoh493xbSaKYV9yLtEapaGQ7J31gdCiDQHGSd86PNo8B",
60+
Large: "QmUWuTZhjUuY8VYWVZrcodsrsbQvckSZwTRxmJ3Avhnw1y",
61+
},
62+
PriceModifier: int64(rand.Intn(50)),
63+
}
64+
65+
// Ensure name is <= 40 chars
66+
if len(options[i].Variants[j].Name) > 40 {
67+
options[i].Variants[j].Name = options[i].Variants[j].Name[:40]
68+
}
69+
}
70+
}
71+
72+
countries := make([]pb.CountryCode, rand.Intn(254)+1)
73+
for i := 0; i < len(countries); i++ {
74+
countries[i] = pb.CountryCode(rand.Intn(255))
75+
}
76+
77+
return &pb.ListingReqApi{
78+
Listing: &pb.Listing{
79+
Slug: slug,
80+
Metadata: &pb.Listing_Metadata{
81+
Version: 1,
82+
AcceptedCurrency: "btc",
83+
PricingCurrency: "btc",
84+
Expiry: &timestamp.Timestamp{Seconds: 2147483647},
85+
Format: pb.Listing_Metadata_FIXED_PRICE,
86+
ContractType: pb.Listing_Metadata_ContractType(uint32(rand.Intn(3))),
87+
},
88+
Item: &pb.Listing_Item{
89+
Sku: sku,
90+
Title: title,
91+
Tags: tags,
92+
Options: options,
93+
Nsfw: isNSFW(),
94+
Description: fake.Paragraphs(),
95+
Price: uint64(rand.Intn(9999)),
96+
ProcessingTime: strconv.Itoa(rand.Intn(14)+1) + " days",
97+
Categories: []string{categories[rand.Intn(len(categories))]},
98+
Grams: float32(rand.Intn(5000)),
99+
Condition: conditions[rand.Intn(len(conditions))],
100+
Images: []*pb.Listing_Item_Image{
101+
{
102+
Filename: "example.jpg",
103+
Original: "QmdfiTnhj1oqiCDmhxu1gdgW6ZqtR7D6ZE7j7CqWUHgKJ8",
104+
Tiny: "QmbKPEBbzVwax8rnrdxLepfmNkdTqnw2RSfJE19iax3fLK",
105+
Small: "QmQ77aAsYjs1rxcp7xZ5qUki1RGDGjQ99cok3ynUMF8Sc5",
106+
Medium: "QmVoh493xbSaKYV9yLtEapaGQ7J31gdCiDQHGSd86PNo8B",
107+
Large: "QmUWuTZhjUuY8VYWVZrcodsrsbQvckSZwTRxmJ3Avhnw1y",
108+
},
109+
},
110+
},
111+
ShippingOptions: []*pb.Listing_ShippingOption{
112+
{
113+
Name: "usps",
114+
Type: pb.Listing_ShippingOption_FIXED_PRICE,
115+
Regions: countries,
116+
Services: []*pb.Listing_ShippingOption_Service{
117+
{
118+
Name: "standard",
119+
Price: uint64(rand.Intn(999)),
120+
EstimatedDelivery: fake.Digits() + " days",
121+
},
122+
},
123+
ShippingRules: &pb.Listing_ShippingOption_ShippingRules{
124+
RuleType: pb.Listing_ShippingOption_ShippingRules_FLAT_FEE_QUANTITY_RANGE,
125+
Rules: []*pb.Listing_ShippingOption_ShippingRules_Rule{
126+
{
127+
MinRange: 0,
128+
MaxRange: 99999999,
129+
Price: uint64(rand.Intn(999)),
130+
},
131+
},
132+
},
133+
},
134+
},
135+
136+
TermsAndConditions: fake.Sentences(),
137+
RefundPolicy: fake.Sentence(),
138+
},
139+
}
140+
}

0 commit comments

Comments
 (0)