Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
dms3
go-dms3
Commits
ba285801
Unverified
Commit
ba285801
authored
Mar 13, 2020
by
Steven Allen
Committed by
GitHub
Mar 13, 2020
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #6949 from olizilla/docker-tag-from-ci
feat: docker build and tag from ci
parents
4292a92f
ec220ddd
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
157 additions
and
0 deletions
+157
-0
.circleci/config.yml
.circleci/config.yml
+80
-0
bin/push-docker-tags.sh
bin/push-docker-tags.sh
+77
-0
No files found.
.circleci/config.yml
View file @
ba285801
...
...
@@ -16,6 +16,11 @@ aliases:
paths
:
-
~/go/pkg/mod
-
~/.cache/go-build/
only-version-tags
:
&only-version-tags
tags
:
only
:
/^v[0-9].*/
branches
:
ignore
:
/.*/
default_environment
:
&default_environment
SERVICE
:
circle-ci
...
...
@@ -53,6 +58,12 @@ executors:
IPFS_REUSEPORT
:
false
LIBP2P_ALLOW_WEAK_RSA_KEYS
:
1
E2E_IPFSD_TYPE
:
go
dockerizer
:
docker
:
-
image
:
circleci/golang:1.14
environment
:
IMAGE_NAME
:
ipfs/go-ipfs
WIP_IMAGE_TAG
:
wip
jobs
:
gobuild
:
...
...
@@ -295,8 +306,45 @@ jobs:
key
:
v1-ipfs-webui-{{ checksum "~/ipfs/go-ipfs/ipfs-webui/package-lock.json" }}
paths
:
-
~/ipfs/go-ipfs/ipfs-webui/node_modules
docker-build
:
executor
:
dockerizer
steps
:
-
checkout
-
setup_remote_docker
:
version
:
"
18.09.3"
-
run
:
name
:
Build Docker image
command
:
|
docker build -t $IMAGE_NAME:$WIP_IMAGE_TAG .
-
run
:
name
:
Archive Docker image
command
:
docker save -o go-ipfs-image.tar $IMAGE_NAME
-
persist_to_workspace
:
root
:
.
paths
:
-
./go-ipfs-image.tar
docker-push
:
executor
:
dockerizer
steps
:
-
checkout
-
setup_remote_docker
:
version
:
"
18.09.3"
-
attach_workspace
:
at
:
/tmp/workspace
-
run
:
name
:
Load archived Docker image
command
:
docker load -i /tmp/workspace/go-ipfs-image.tar
-
run
:
name
:
Publish Docker Image to Docker Hub
command
:
|
echo "$DOCKERHUB_PASS" | docker login -u "$DOCKERHUB_USERNAME" --password-stdin
./bin/push-docker-tags.sh $(date -u +%F) "$CIRCLE_SHA1" "$CIRCLE_BRANCH" "$CIRCLE_TAG"
workflows
:
version
:
2
# Runs for all branches, but not on tags
# see: https://circleci.com/docs/2.0/workflows/#executing-workflows-for-a-git-tag
test
:
jobs
:
-
gobuild
...
...
@@ -316,3 +364,35 @@ workflows:
-
ipfs-webui
:
requires
:
-
build
-
docker-build
-
docker-push
:
# Requires dockerhub credentials, from circleci context.
context
:
dockerhub
requires
:
-
docker-build
-
golint
-
gotest
-
sharness
-
interop
-
go-ipfs-api
-
go-ipfs-http-client
-
ipfs-webui
filters
:
branches
:
only
:
-
master
-
feat/stabilize-dht
# NOTE: CircleCI only builds tags if you explicitly filter for them. That
# also means tag-based jobs can only depend on other tag-based jobs, so we
# use a separate workflow because every job needs to be tagged together.
# see: https://circleci.com/docs/2.0/workflows/#executing-workflows-for-a-git-tag
docker-on-tag
:
jobs
:
-
docker-build
:
filters
:
*only-version-tags
-
docker-push
:
context
:
dockerhub
filters
:
*only-version-tags
requires
:
-
docker-build
bin/push-docker-tags.sh
0 → 100755
View file @
ba285801
#!/usr/bin/env bash
# push-docker-tags.sh
#
# Run from ci to tag images based on the current branch or tag name.
# A bit like dockerhub autobuild config, but somewhere we can version control it.
#
# The `docker-build` job in .circleci/config.yml builds the current commit
# in docker and tags it as ipfs/go-ipfs:wip
#
# Then the `docker-publish` job runs this script to decide what tag, if any,
# to publish to dockerhub.
#
# Usage:
# ./push-docker-tags.sh <build number> <git commit sha1> <git branch name> [git tag name] [dry run]
#
# Example:
# # dry run. pass a 5th arg to have it print what it would do rather than do it.
# ./push-docker-tags.sh $(date -u +%F) testingsha master "" dryrun
#
# # push tag for the master branch
# ./push-docker-tags.sh $(date -u +%F) testingsha master
#
# # push tag for a release tag
# ./push-docker-tags.sh $(date -u +%F) testingsha release v0.5.0
#
# # Serving suggestion in circle ci - https://circleci.com/docs/2.0/env-vars/#built-in-environment-variables
# ./push-docker-tags.sh $(date -u +%F) "$CIRCLE_SHA1" "$CIRCLE_BRANCH" "$CIRCLE_TAG"
#
set
-euo
pipefail
if
[[
$#
-lt
3
]]
;
then
echo
'At least 3 args required. Pass 5 args for a dry run.'
echo
'Usage:'
echo
'./push-docker-tags.sh <build number> <git commit sha1> <git branch name> [git tag name] [dry run]'
exit
1
fi
BUILD_NUM
=
$1
GIT_SHA1
=
$2
GIT_SHA1_SHORT
=
$(
echo
"
$GIT_SHA1
"
|
cut
-c
1-7
)
GIT_BRANCH
=
$3
GIT_TAG
=
${
4
:-
""
}
DRY_RUN
=
${
5
:-
false
}
WIP_IMAGE_TAG
=
${
WIP_IMAGE_TAG
:-
wip
}
IMAGE_NAME
=
${
IMAGE_NAME
:-
ipfs
/go-ipfs
}
pushTag
()
{
local
IMAGE_TAG
=
$1
if
[
"
$DRY_RUN
"
!=
false
]
;
then
echo
"DRY RUN! I would have tagged and pushed the following..."
echo
docker tag
"
$IMAGE_NAME
:
$WIP_IMAGE_TAG
"
"
$IMAGE_NAME
:
$IMAGE_TAG
"
echo
docker push
"
$IMAGE_NAME
:
$IMAGE_TAG
"
else
echo
"Tagging
$IMAGE_NAME
:
$IMAGE_TAG
and pushing to dockerhub"
docker tag
"
$IMAGE_NAME
:
$WIP_IMAGE_TAG
"
"
$IMAGE_NAME
:
$IMAGE_TAG
"
docker push
"
$IMAGE_NAME
:
$IMAGE_TAG
"
fi
}
if
[[
$GIT_TAG
=
~ ^v[0-9]+
]]
;
then
pushTag
"
$GIT_TAG
"
pushTag
"latest"
elif
[
"
$GIT_BRANCH
"
=
"feat/stabilize-dht"
]
;
then
pushTag
"bifrost-
${
BUILD_NUM
}
-
${
GIT_SHA1_SHORT
}
"
pushTag
"bifrost-latest"
elif
[
"
$GIT_BRANCH
"
=
"master"
]
;
then
pushTag
"master-
${
BUILD_NUM
}
-
${
GIT_SHA1_SHORT
}
"
pushTag
"master-latest"
else
echo
"Nothing to do. No docker tag defined for branch:
$GIT_BRANCH
, tag:
$GIT_TAG
"
fi
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