Skip to content

Commit f5c5488

Browse files
committed
Add dockerfile and initial CI pipeline
1 parent 293349f commit f5c5488

File tree

3 files changed

+255
-0
lines changed

3 files changed

+255
-0
lines changed

.circleci/config.yml

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
version: 2.1
2+
3+
orbs:
4+
slack: circleci/[email protected]
5+
6+
workflows:
7+
main-workflow:
8+
jobs:
9+
- download-taskagent:
10+
context: org-global
11+
- scan-image:
12+
context: org-global
13+
requires:
14+
- download-taskagent
15+
- build-and-publish-image:
16+
name: build-and-publish-image-amd64
17+
context: org-global
18+
requires:
19+
- scan-image
20+
- build-and-publish-image:
21+
name: build-and-publish-image-arm64
22+
resource: arm.medium
23+
arch: arm64
24+
context: org-global
25+
requires:
26+
- scan-image
27+
28+
executors:
29+
ccc:
30+
docker:
31+
- image: circleci/command-convenience:0.1
32+
auth:
33+
username: $DOCKER_HUB_USER
34+
password: $DOCKER_HUB_PASSWORD
35+
environment:
36+
NAME: << pipeline.parameters.release-name >>
37+
DOCKERFILE_PATH: Dockerfile
38+
TEAM: on-prem
39+
40+
parameters:
41+
release-name:
42+
type: string
43+
default: "runner-init"
44+
45+
jobs:
46+
download-taskagent:
47+
machine:
48+
image: ubuntu-2204:2024.02.7
49+
resource_class: small
50+
steps:
51+
- checkout
52+
- docker_login
53+
- run: ./do download-taskagent amd64
54+
- run: ./do download-taskagent arm64
55+
- persist_to_workspace:
56+
root: .
57+
paths:
58+
- "./circleci-agent-*"
59+
- notify_failing_main
60+
61+
build-and-publish-image:
62+
parameters:
63+
resource:
64+
type: string
65+
default: small
66+
arch:
67+
type: string
68+
default: amd64
69+
machine:
70+
image: ubuntu-2204:2024.02.7
71+
resource_class: << parameters.resource>>
72+
steps:
73+
- checkout
74+
- attach_workspace:
75+
at: .
76+
- docker_login
77+
- run: docker build -t circleci/<< pipeline.parameters.release-name >>:agent-<< parameters.arch >> --build-arg ARCH=<< parameters.arch >> .
78+
# TODO: Publish images (on main) once the repo is set up
79+
- notify_failing_main
80+
81+
scan-image:
82+
executor: ccc
83+
steps:
84+
- checkout
85+
- setup_remote_docker
86+
- attach_workspace:
87+
at: .
88+
- run:
89+
name: Scan Docker images
90+
command: scan
91+
- store_artifacts:
92+
path: ccc-image-scan-results
93+
- notify_failing_main
94+
95+
commands:
96+
docker_login:
97+
steps:
98+
- run:
99+
name: "Log into Docker Hub"
100+
command: |
101+
docker login -u "${DOCKER_HUB_USER}" -p "${DOCKER_HUB_PASSWORD}"
102+
103+
notify_failing_main:
104+
steps:
105+
- slack/notify:
106+
channel: runner-alerts
107+
branch_pattern: main
108+
event: fail
109+
template: basic_fail_1

Dockerfile

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
FROM busybox:stable-musl as build
2+
3+
FROM scratch as temp
4+
5+
ARG ARCH=amd64
6+
7+
COPY ./circleci-agent-${ARCH} /opt/circleci/circleci-agent
8+
COPY --from=build /bin/cp /bin/cp
9+
10+
FROM scratch
11+
12+
COPY --from=temp / /
13+
14+
CMD ["/bin/cp"]

do

Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
#!/usr/bin/env bash
2+
3+
set -eu -o pipefail
4+
5+
# This variable is used, but shellcheck can't tell.
6+
# shellcheck disable=SC2034
7+
help_download_taskagent="Download task agent via the picard image"
8+
download-taskagent() {
9+
arch=${1:?'task agent arch must be specified'}
10+
11+
id=$(docker create circleci/picard:agent)
12+
docker cp "$id":/opt/circleci/linux/"$arch"/circleci-agent ./circleci-agent-"$arch"
13+
docker rm -v "$id"
14+
}
15+
16+
help-text-intro() {
17+
echo "
18+
DO
19+
20+
A set of simple repetitive tasks that adds minimally
21+
to standard tools used to build and test the service.
22+
(e.g. go and docker)
23+
"
24+
}
25+
26+
### START FRAMEWORK ###
27+
# Do Version 0.0.4
28+
29+
# This variable is used, but shellcheck can't tell.
30+
# shellcheck disable=SC2034
31+
help_completion="Print shell completion function for this script.
32+
33+
Usage: $0 completion SHELL"
34+
completion() {
35+
local shell
36+
shell="${1-}"
37+
38+
if [ -z "$shell" ]; then
39+
echo "Usage: $0 completion SHELL" 1>&2
40+
exit 1
41+
fi
42+
43+
case "$shell" in
44+
bash)
45+
(
46+
echo
47+
echo '_dotslashdo_completions() { '
48+
# shellcheck disable=SC2016
49+
echo ' COMPREPLY=($(compgen -W "$('"$0"' list)" "${COMP_WORDS[1]}"))'
50+
echo '}'
51+
echo 'complete -F _dotslashdo_completions '"$0"
52+
)
53+
;;
54+
zsh)
55+
cat <<EOF
56+
_dotslashdo_completions() {
57+
local -a subcmds
58+
subcmds=()
59+
DO_HELP_SKIP_INTRO=1 $0 help | while read line; do
60+
EOF
61+
cat <<'EOF'
62+
cmd=$(cut -f1 <<< $line)
63+
cmd=$(awk '{$1=$1};1' <<< $cmd)
64+
65+
desc=$(cut -f2- <<< $line)
66+
desc=$(awk '{$1=$1};1' <<< $desc)
67+
68+
subcmds+=("$cmd:$desc")
69+
done
70+
_describe 'do' subcmds
71+
}
72+
73+
compdef _dotslashdo_completions do
74+
EOF
75+
;;
76+
fish)
77+
cat <<EOF
78+
complete -e -c do
79+
complete -f -c do
80+
for line in (string split \n (DO_HELP_SKIP_INTRO=1 $0 help))
81+
EOF
82+
cat <<'EOF'
83+
set cmd (string split \t $line)
84+
complete -c do -a $cmd[1] -d $cmd[2]
85+
end
86+
EOF
87+
;;
88+
esac
89+
}
90+
91+
list() {
92+
declare -F | awk '{print $3}'
93+
}
94+
95+
# This variable is used, but shellcheck can't tell.
96+
# shellcheck disable=SC2034
97+
help_help="Print help text, or detailed help for a task."
98+
help() {
99+
local item
100+
item="${1-}"
101+
if [ -n "${item}" ]; then
102+
local help_name
103+
help_name="help_${item//-/_}"
104+
echo "${!help_name-}"
105+
return
106+
fi
107+
108+
if [ -z "${DO_HELP_SKIP_INTRO-}" ]; then
109+
type -t help-text-intro >/dev/null && help-text-intro
110+
fi
111+
for item in $(list); do
112+
local help_name text
113+
help_name="help_${item//-/_}"
114+
text="${!help_name-}"
115+
[ -n "$text" ] && printf "%-30s\t%s\n" "$item" "$(echo "$text" | head -1)"
116+
done
117+
}
118+
119+
case "${1-}" in
120+
list) list ;;
121+
"" | "help") help "${2-}" ;;
122+
*)
123+
if ! declare -F "${1}" >/dev/null; then
124+
printf "Unknown target: %s\n\n" "${1}"
125+
help
126+
exit 1
127+
else
128+
"$@"
129+
fi
130+
;;
131+
esac
132+
### END FRAMEWORK ###

0 commit comments

Comments
 (0)