This repository has been archived by the owner on Jul 22, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #176 from IBM/dev
Merge dev GA v1.0.0 to master branch
- Loading branch information
Showing
84 changed files
with
10,619 additions
and
1,867 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
language: go | ||
|
||
go: | ||
- 1.7 | ||
- 1.9 | ||
|
||
install: | ||
- sh scripts/run_glide_up | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
FROM golang:1.9.1 | ||
WORKDIR /go/src/github.com/IBM/ubiquity/ | ||
COPY . . | ||
RUN go get -v github.com/Masterminds/glide | ||
RUN glide up | ||
RUN CGO_ENABLED=1 GOOS=linux go build -tags netgo -v -a --ldflags '-w -linkmode external -extldflags "-static"' -installsuffix cgo -o ubiquity main.go | ||
|
||
|
||
FROM alpine:latest | ||
RUN apk --no-cache add ca-certificates=20161130-r2 openssl=1.0.2k-r0 | ||
WORKDIR /root/ | ||
COPY --from=0 /go/src/github.com/IBM/ubiquity/ubiquity . | ||
COPY --from=0 /go/src/github.com/IBM/ubiquity/LICENSE . | ||
COPY --from=0 /go/src/github.com/IBM/ubiquity/scripts/notices_file_for_ibm_storage_enabler_for_containers ./NOTICES | ||
|
||
COPY docker-entrypoint.sh . | ||
RUN chmod 755 docker-entrypoint.sh | ||
|
||
# comments below should be removed when we implement the new SSL_MODE env variable | ||
ENV PATH=/root:$PATH \ | ||
UBIQUITY_SERVER_CERT_PRIVATE=/var/lib/ubiquity/ssl/private/ubiquity.key \ | ||
UBIQUITY_SERVER_CERT_PUBLIC=/var/lib/ubiquity/ssl/private/ubiquity.crt \ | ||
UBIQUITY_SERVER_VERIFY_SCBE_CERT=/var/lib/ubiquity/ssl/public/scbe-trusted-ca.crt \ | ||
UBIQUITY_DB_SSL_ROOT_CERT=/var/lib/ubiquity/ssl/public/ubiquity-db-trusted-ca.crt \ | ||
SSL_MODE=verify-full | ||
|
||
ENTRYPOINT ["docker-entrypoint.sh"] | ||
CMD ["ubiquity"] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
/** | ||
* Copyright 2017 IBM Corp. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package database | ||
|
||
import ( | ||
"github.com/jinzhu/gorm" | ||
_ "github.com/jinzhu/gorm/dialects/postgres" | ||
_ "github.com/jinzhu/gorm/dialects/sqlite" | ||
"github.com/IBM/ubiquity/utils/logs" | ||
"errors" | ||
) | ||
|
||
var globalConnectionFactory ConnectionFactory = nil | ||
|
||
func initConnectionFactory(connectionFactory ConnectionFactory) func() { | ||
if globalConnectionFactory != nil { | ||
panic("globalConnectionFactory already initialized") | ||
} | ||
globalConnectionFactory = connectionFactory | ||
return func() { globalConnectionFactory = nil } | ||
} | ||
|
||
type ConnectionFactory interface { | ||
newConnection() (*gorm.DB, error) | ||
} | ||
|
||
type postgresFactory struct { | ||
psql string | ||
psqlLog string | ||
} | ||
|
||
type sqliteFactory struct { | ||
path string | ||
} | ||
|
||
type testErrorFactory struct { | ||
} | ||
|
||
func (f *postgresFactory) newConnection() (*gorm.DB, error) { | ||
logger := logs.GetLogger() | ||
logger.Debug("", logs.Args{{"psql", f.psqlLog}}) | ||
return gorm.Open("postgres", f.psql) | ||
} | ||
|
||
func (f *sqliteFactory) newConnection() (*gorm.DB, error) { | ||
return gorm.Open("sqlite3", f.path) | ||
} | ||
|
||
func (f *testErrorFactory) newConnection() (*gorm.DB, error) { | ||
return nil, errors.New("testErrorFactory") | ||
} | ||
|
||
type Connection struct { | ||
factory ConnectionFactory | ||
logger logs.Logger | ||
db *gorm.DB | ||
} | ||
|
||
func NewConnection() Connection { | ||
return Connection{logger: logs.GetLogger(), factory: globalConnectionFactory} | ||
} | ||
|
||
func (c *Connection) Open() (error) { | ||
defer c.logger.Trace(logs.DEBUG)() | ||
var err error | ||
|
||
// sanity | ||
if c.db != nil { | ||
return c.logger.ErrorRet(errors.New("Connection already open"), "failed") | ||
} | ||
|
||
// open db connection | ||
if c.db, err = c.factory.newConnection(); err != nil { | ||
return c.logger.ErrorRet(err, "failed") | ||
} | ||
|
||
// do migrations | ||
if err = doMigrations(*c); err != nil { | ||
defer c.Close() | ||
return c.logger.ErrorRet(err, "doMigrations failed") | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func (c *Connection) Close() (error) { | ||
defer c.logger.Trace(logs.DEBUG)() | ||
var err error | ||
|
||
// sanity | ||
if c.db == nil { | ||
return c.logger.ErrorRet(errors.New("Connection already closed"), "failed") | ||
} | ||
|
||
// close db connection | ||
err = c.db.Close() | ||
c.db = nil | ||
if err != nil { | ||
return c.logger.ErrorRet(err, "failed") | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func (c *Connection) GetDb() (*gorm.DB) { | ||
defer c.logger.Trace(logs.DEBUG)() | ||
|
||
return c.db | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/** | ||
* Copyright 2017 IBM Corp. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package database_test | ||
|
||
|
||
import ( | ||
. "github.com/onsi/ginkgo" | ||
. "github.com/onsi/gomega" | ||
"github.com/IBM/ubiquity/database" | ||
) | ||
|
||
|
||
var _ = Describe("Connection", func() { | ||
var ( | ||
err error | ||
) | ||
BeforeEach(func() { | ||
}) | ||
|
||
Context(".Open and Close", func() { | ||
It("open and close success", func() { | ||
dbConnection := database.NewConnection() | ||
Expect(dbConnection.GetDb()).To(BeNil()) | ||
err = dbConnection.Open() | ||
Expect(err).To(Not(HaveOccurred())) | ||
Expect(dbConnection.GetDb()).To(Not(BeNil())) | ||
err = dbConnection.Close() | ||
Expect(err).To(Not(HaveOccurred())) | ||
Expect(dbConnection.GetDb()).To(BeNil()) | ||
}) | ||
It("open fail", func() { | ||
dbConnection := database.NewConnection() | ||
Expect(dbConnection.GetDb()).To(BeNil()) | ||
err = dbConnection.Open() | ||
Expect(err).To(Not(HaveOccurred())) | ||
Expect(dbConnection.GetDb()).To(Not(BeNil())) | ||
err = dbConnection.Open() | ||
Expect(err).To(HaveOccurred()) | ||
err = dbConnection.Close() | ||
Expect(err).To(Not(HaveOccurred())) | ||
Expect(dbConnection.GetDb()).To(BeNil()) | ||
}) | ||
It("close fail", func() { | ||
dbConnection := database.NewConnection() | ||
Expect(dbConnection.GetDb()).To(BeNil()) | ||
err = dbConnection.Close() | ||
Expect(err).To(HaveOccurred()) | ||
}) | ||
}) | ||
}) |
Oops, something went wrong.