Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
danet
goSDN
Commits
b3babef2
Commit
b3babef2
authored
Mar 29, 2021
by
Manuel Kieweg
🤷
Browse files
Merge branch 'refactor-container-deployment' into 'develop'
Refactor container deployment See merge request cocsn/gosdn!123
parents
a71d4d59
b603d6e7
Changes
7
Hide whitespace changes
Inline
Side-by-side
build/ci/.build-container.yml
View file @
b3babef2
...
...
@@ -6,7 +6,7 @@ variables:
DOCKER_TLS_CERTDIR
:
"
/certs"
DOCKER_IMAGE_SHA
:
$CI_REGISTRY_IMAGE:$CI_COMMIT_SHA
.
deploy
:
&deploy
.
build
:
&build
before_script
:
-
echo "override global before script"
image
:
docker:19.03.12
...
...
@@ -18,54 +18,31 @@ variables:
docker build \
--build-arg GITLAB_USER=$GO_MODULES_USER \
--build-arg GITLAB_TOKEN=$GO_MODULES_ACCESS_TOKEN \
-t $DOCKER_IMAGE_SHA
.
-t $DOCKER_IMAGE_SHA
$PATH
-
docker login -u gitlab-ci-token -p $CI_JOB_TOKEN $CI_REGISTRY
-
docker tag $DOCKER_IMAGE_SHA $TAG
-
docker push $TAG
deploy
:develop:
build
:develop:
variables
:
TAG
:
$CI_REGISTRY_IMAGE:develop
HOOK
:
$PORTAINER_HOOK_DEVELOP
PATH
:
build/dockerfiles/staging
rules
:
-
if
:
$CI_COMMIT_BRANCH == "develop"
<<
:
*
deploy
<<
:
*
build
deploy:lat
est:
build:merge-requ
est:
variables
:
TAG
:
$CI_REGISTRY_IMAGE:latest
HOOK
:
$PORTAINER_HOOK_LATEST
rules
:
-
if
:
$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
<<
:
*deploy
.deploy:mr: &deploy-mr
before_script
:
-
echo "override global before script"
image
:
docker:19.03.12
stage
:
build
tags
:
-
dind
script
:
-
>
docker build \
--build-arg GITLAB_USER=$GO_MODULES_USER \
--build-arg GITLAB_TOKEN=$GO_MODULES_ACCESS_TOKEN \
-t $DOCKER_IMAGE_SHA .
-
docker login -u gitlab-ci-token -p $CI_JOB_TOKEN $CI_REGISTRY
-
docker tag $DOCKER_IMAGE_SHA $TAG
-
docker push $TAG
deploy:merge-request:master:
variables
:
TAG
:
$CI_REGISTRY_IMAGE:mr-master
TAG
:
$CI_REGISTRY_IMAGE:merge-request
PATH
:
build/dockerfiles/staging
rules
:
-
if
:
$CI_PIPELINE_SOURCE == "merge_request_event"
&& $CI_MERGE_REQUEST_TARGET_BRANCH_NAME == $CI_DEFAULT_BRANCH
<<
:
*
deploy-mr
-
if
:
$CI_PIPELINE_SOURCE == "merge_request_event"
<<
:
*
build
deploy:merge-mr:develop
:
build:latest
:
variables
:
TAG
:
$CI_REGISTRY_IMAGE:mr-develop
TAG
:
$CI_REGISTRY_IMAGE:latest
PATH
:
build/dockerfiles/production
rules
:
-
if
:
$CI_
PIPELINE_SOURCE == "merge_request_event" && $CI_MERGE_REQUEST_TARGET_BRANCH_NAME == 'develop'
<<
:
*
deploy-mr
-
if
:
$CI_
COMMIT_BRANCH == $CI_DEFAULT_BRANCH
<<
:
*
build
\ No newline at end of file
build/ci/.terraform-ci.yml
View file @
b3babef2
...
...
@@ -21,12 +21,9 @@ cache:
-
export TF_VAR_tls_cert=${DOCKER_TLS_CERT}
-
export TF_VAR_tls_ca_cert=${DOCKER_TLS_CA}
rules
:
-
if
:
$CI_PIPELINE_SOURCE == "merge_request_event" && $CI_MERGE_REQUEST_TARGET_BRANCH_NAME == $CI_DEFAULT_BRANCH
-
if
:
$CI_PIPELINE_SOURCE == "merge_request_event" &&
(
$CI_MERGE_REQUEST_TARGET_BRANCH_NAME == $CI_DEFAULT_BRANCH
|| $CI_MERGE_REQUEST_TARGET_BRANCH_NAME == 'develop')
variables
:
TF_VAR_container_tag
:
$CI_REGISTRY_IMAGE:mr-master
-
if
:
$CI_PIPELINE_SOURCE == "merge_request_event" && $CI_MERGE_REQUEST_TARGET_BRANCH_NAME == 'develop'
variables
:
TF_VAR_container_tag
:
$CI_REGISTRY_IMAGE:mr-develop
TF_VAR_container_tag
:
$CI_REGISTRY_IMAGE:merge-request
-
if
:
$CI_COMMIT_BRANCH == "integration-test"
-
if
:
$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
...
...
build/dockerfiles/production/Dockerfile
0 → 100644
View file @
b3babef2
FROM
golang:1.15-alpine AS builder
ARG
GITLAB_USER
ARG
GITLAB_TOKEN
WORKDIR
/src/gosdn
COPY
. .
RUN
apk add git
RUN
git config
--global
url.
"https://
$GITLAB_USER
:
$GITLAB_TOKEN
@code.fbi.h-da.de"
.insteadOf
"https://code.fbi.h-da.de"
RUN
go mod download
RUN
CGO_ENABLED
=
0
GOOS
=
linux go build ./cmd/gosdn
FROM
alpine:latest
EXPOSE
8443
EXPOSE
55055
COPY
--from=builder /src/gosdn/gosdn .
COPY
--from=builder /src/gosdn/configs ./configs
ENTRYPOINT
[ "./gosdn" ]
CMD
[""]
build/dockerfiles/staging/Dockerfile
0 → 100644
View file @
b3babef2
FROM
golang:1.15-alpine AS builder
ARG
GITLAB_USER
ARG
GITLAB_TOKEN
WORKDIR
/src/gosdn
COPY
. .
RUN
apk add git
RUN
git config
--global
url.
"https://
$GITLAB_USER
:
$GITLAB_TOKEN
@code.fbi.h-da.de"
.insteadOf
"https://code.fbi.h-da.de"
RUN
go mod download
RUN
CGO_ENABLED
=
0
GOOS
=
linux go build
-race
./cmd/gosdn
FROM
alpine:latest
EXPOSE
8443
EXPOSE
55055
COPY
--from=builder /src/gosdn/gosdn .
COPY
--from=builder /src/gosdn/configs ./configs
ENTRYPOINT
[ "./gosdn" ]
CMD
[""]
nucleus/controller.go
View file @
b3babef2
...
...
@@ -47,19 +47,8 @@ func initialize() error {
}
// TODO: Start grpc listener here
if
err
:=
httpAPI
();
err
!=
nil
{
return
err
}
attachDatabase
()
return
nil
}
// deprecated
// attachDatabase connects to the database and passes the connection to the controller core
func
attachDatabase
()
{
c
.
database
=
database
.
NewDatabaseClient
()
return
httpAPI
()
}
// createSouthboundInterfaces initializes the controller with its supported SBIs
...
...
@@ -87,9 +76,11 @@ func createPrincipalNetworkDomain(sbi SouthboundInterface) error {
// Run calls initialize to start the controller
func
Run
(
ctx
context
.
Context
)
error
{
var
initError
error
coreLock
.
Lock
()
coreOnce
.
Do
(
func
()
{
initError
=
initialize
()
})
coreLock
.
Unlock
()
if
initError
!=
nil
{
log
.
WithFields
(
log
.
Fields
{})
.
Error
(
initError
)
return
initError
...
...
nucleus/http.go
View file @
b3babef2
...
...
@@ -9,12 +9,9 @@ import (
log
"github.com/sirupsen/logrus"
"net/http"
"net/url"
"sync"
"time"
)
var
httpOnce
sync
.
Once
func
stopHttpServer
()
error
{
ctx
,
cancel
:=
context
.
WithTimeout
(
context
.
Background
(),
5
*
time
.
Second
)
defer
cancel
()
...
...
@@ -34,16 +31,11 @@ func registerHttpHandler() {
}
// deprecated
func
httpAPI
()
(
err
error
)
{
coreLock
.
Lock
()
defer
coreLock
.
Unlock
()
httpOnce
.
Do
(
registerHttpHandler
)
func
httpAPI
()
error
{
registerHttpHandler
()
c
.
httpServer
=
&
http
.
Server
{
Addr
:
":8080"
}
go
func
()
{
err
=
c
.
httpServer
.
ListenAndServe
()
if
err
!=
nil
{
return
}
log
.
Info
(
c
.
httpServer
.
ListenAndServe
())
}()
return
nil
}
...
...
nucleus/ini
z
ali
z
e_test.go
→
nucleus/ini
ti
ali
s
e_test.go
View file @
b3babef2
...
...
@@ -45,6 +45,12 @@ var gnmiAddress = "141.100.70.171:6030"
// TODO: Move somewhere more sensible
func
TestMain
(
m
*
testing
.
M
)
{
log
.
SetReportCaller
(
true
)
if
os
.
Getenv
(
"GOSDN_LOG"
)
==
"nolog"
{
log
.
SetLevel
(
log
.
PanicLevel
)
}
gnmiMessages
=
map
[
string
]
pb
.
Message
{
"../test/proto/cap-resp-arista-ceos"
:
&
gpb
.
CapabilityResponse
{},
"../test/proto/req-full-node"
:
&
gpb
.
GetRequest
{},
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment