xref: /openbmc/docs/testing/local-ci-build.md (revision 73f9bc12)
1*73f9bc12SGunnar Mills# Local CI Build
2*73f9bc12SGunnar Mills
3*73f9bc12SGunnar MillsThese instructions pertain to running the upstream OpenBMC CI locally.
4*73f9bc12SGunnar Mills
5*73f9bc12SGunnar Mills## Install Docker
6*73f9bc12SGunnar Mills
7*73f9bc12SGunnar MillsPlease install and configure Docker. The installation of Docker CE (Community
8*73f9bc12SGunnar MillsEdition) varies by platform and may differ in your organization, but the
9*73f9bc12SGunnar Mills[Docker Docs](https://docs.docker.com/install/) are a good place to start
10*73f9bc12SGunnar Millslooking.
11*73f9bc12SGunnar Mills
12*73f9bc12SGunnar MillsCheck that the installation was successful by running `sudo docker run
13*73f9bc12SGunnar Millshello-world`.
14*73f9bc12SGunnar Mills
15*73f9bc12SGunnar MillsEach repository is built locally within the CI using the bootstrap.sh and
16*73f9bc12SGunnar Millsautomake toolchain.
17*73f9bc12SGunnar Mills
18*73f9bc12SGunnar Mills## Download the CI Image
19*73f9bc12SGunnar Mills
20*73f9bc12SGunnar MillsStart by making a place for your CI repositories to live, and clone the CI
21*73f9bc12SGunnar Millsscripts first:
22*73f9bc12SGunnar Mills
23*73f9bc12SGunnar Mills```shell
24*73f9bc12SGunnar Millsmkdir ci_test_area
25*73f9bc12SGunnar Millscd ci_test_area
26*73f9bc12SGunnar Millsgit clone https://github.com/openbmc/openbmc-build-scripts.git
27*73f9bc12SGunnar Mills```
28*73f9bc12SGunnar Mills
29*73f9bc12SGunnar Mills## Add a Read-Only Repo
30*73f9bc12SGunnar Mills
31*73f9bc12SGunnar MillsIf you just want to validate a project as it is upstream, without any of your
32*73f9bc12SGunnar Millsown changes, you can clone it directly into the Docker directory. This example
33*73f9bc12SGunnar Millsclones and builds phosphor-hwmon directly. The upstream CI will try building
34*73f9bc12SGunnar Millseverything and this includes running `make check` if available. It will also run
35*73f9bc12SGunnar Mills`format-code.sh` and check if the code is formatted properly if there is a
36*73f9bc12SGunnar Mills`.clang-format` file present in the target repository, or if there is a script
37*73f9bc12SGunnar Millsin the repo named `format-code.sh`.
38*73f9bc12SGunnar Mills
39*73f9bc12SGunnar Mills```shell
40*73f9bc12SGunnar Millscd /path/to/ci_test_area
41*73f9bc12SGunnar Millsgit clone https://github.com/openbmc/phosphor-hwmon
42*73f9bc12SGunnar MillsWORKSPACE=$(pwd) UNIT_TEST_PKG=phosphor-hwmon \
43*73f9bc12SGunnar Mills./openbmc-build-scripts/run-unit-test-docker.sh
44*73f9bc12SGunnar Mills```
45*73f9bc12SGunnar Mills
46*73f9bc12SGunnar MillsNOTE: When running 'run-unit-test-docker.sh' make sure you do not have any
47*73f9bc12SGunnar Millsuncommitted changes. The script runs git diff after 'format-code.sh' and
48*73f9bc12SGunnar Millstherefore any uncommitted changes show up as output and it then fails assuming
49*73f9bc12SGunnar Millsthe code was improperly formatted.
50*73f9bc12SGunnar Mills
51*73f9bc12SGunnar MillsNOTE: This technique is okay if you have only a quick change on a project you
52*73f9bc12SGunnar Millsdon't work on very often, but is more difficult to use if you would rather use
53*73f9bc12SGunnar Millsan active development branch. If you plan to develop regularly on a repo, use
54*73f9bc12SGunnar Millsthe next technique instead.
55*73f9bc12SGunnar Mills
56*73f9bc12SGunnar Mills## Reference an Existing Repo with `git worktree`
57*73f9bc12SGunnar Mills
58*73f9bc12SGunnar MillsIf you're actively developing on a local copy of a repo already, or you want to
59*73f9bc12SGunnar Millsstart doing so, you should use `git worktree` instead so that the Docker
60*73f9bc12SGunnar Millscontainer can reference a specific branch of your existing local repo. Learn
61*73f9bc12SGunnar Millsmore about worktree by running `git help worktree` if you're curious.
62*73f9bc12SGunnar Mills
63*73f9bc12SGunnar MillsThis example demonstrates how to make a worktree of `phosphor-host-ipmid` in
64*73f9bc12SGunnar Millsyour Docker container.
65*73f9bc12SGunnar Mills
66*73f9bc12SGunnar Mills```shell
67*73f9bc12SGunnar Millscd /my/dir/for/phosphor-host-ipmid
68*73f9bc12SGunnar Millsgit worktree add /path/to/ci_test_area/phosphor-host-ipmid
69*73f9bc12SGunnar Mills```
70*73f9bc12SGunnar Mills
71*73f9bc12SGunnar MillsNow, if you `cd /path/to/ci_test_area`, you should see a directory
72*73f9bc12SGunnar Mills`phosphor-host-ipmid/`, and if you enter it and run `git status` you will see
73*73f9bc12SGunnar Millsthat you're likely on a new branch named `phosphor-host-ipmid`. This is just for
74*73f9bc12SGunnar Millsconvenience, since you can't check out a branch in your worktree that's already
75*73f9bc12SGunnar Millschecked out somewhere else; you can safely ignore or delete that branch later.
76*73f9bc12SGunnar Mills
77*73f9bc12SGunnar MillsHowever, Git won't be able to figure out how to get to your main worktree
78*73f9bc12SGunnar Mills(`/my/dir/for/phosphor-host-ipmid`), so we'll need to mount it when we run. Open
79*73f9bc12SGunnar Millsup `/path/to/ci_test_area/openbmc-build-scripts/run-unit-test-docker.sh` and
80*73f9bc12SGunnar Millsfind where we call `docker run`, way down at the bottom. Add an additional
81*73f9bc12SGunnar Millsargument, remembering to escape the newline ('\'):
82*73f9bc12SGunnar Mills
83*73f9bc12SGunnar Mills```
84*73f9bc12SGunnar MillsPHOSPHOR_IPMI_HOST_PATH="/my/dir/for/phosphor-host-ipmid"
85*73f9bc12SGunnar Mills
86*73f9bc12SGunnar Millsdocker run --blah-blah-existing-flags \
87*73f9bc12SGunnar Mills  -v ${PHOSPHOR_IPMI_HOST_PATH}:${PHOSPHOR_IPMI_HOST_PATH} \
88*73f9bc12SGunnar Mills  -other \
89*73f9bc12SGunnar Mills  -args
90*73f9bc12SGunnar Mills```
91*73f9bc12SGunnar Mills
92*73f9bc12SGunnar MillsThen commit this, so you can make sure not to lose it if you update the scripts
93*73f9bc12SGunnar Millsrepo:
94*73f9bc12SGunnar Mills
95*73f9bc12SGunnar Mills```shell
96*73f9bc12SGunnar Millscd openbmc-build-scripts
97*73f9bc12SGunnar Millsgit add run-unit-test-docker.sh
98*73f9bc12SGunnar Millsgit commit -m "mount phosphor-host-ipmid"
99*73f9bc12SGunnar Mills```
100*73f9bc12SGunnar Mills
101*73f9bc12SGunnar MillsThe easiest workflow in this situation now looks something like this:
102*73f9bc12SGunnar Mills
103*73f9bc12SGunnar Mills```shell
104*73f9bc12SGunnar Mills# Hack in the main worktree.
105*73f9bc12SGunnar Millscd /my/dir/for/phosphor-host-ipmid
106*73f9bc12SGunnar Millsgit checkout -b add-foo
107*73f9bc12SGunnar Mills# Make a change.
108*73f9bc12SGunnar Millstouch foo
109*73f9bc12SGunnar Mills# Make sure to commit it.
110*73f9bc12SGunnar Millsgit add foo
111*73f9bc12SGunnar Millsgit commit -sm "change foo"
112*73f9bc12SGunnar Mills# Update the Docker worktree to agree with it.
113*73f9bc12SGunnar Millscd /path/to/ci_test_area/phosphor-host-ipmid
114*73f9bc12SGunnar Millsgit checkout --detach add-foo
115*73f9bc12SGunnar Mills# Now run the Docker container normally
116*73f9bc12SGunnar Mills```
117*73f9bc12SGunnar Mills
118*73f9bc12SGunnar Mills#### Interactive Docker Session
119*73f9bc12SGunnar Mills
120*73f9bc12SGunnar MillsTo use an interactive session, you can change the `run-unit-test-docker.sh`.
121*73f9bc12SGunnar Mills
122*73f9bc12SGunnar MillsReplace the following (or similar):
123*73f9bc12SGunnar Mills
124*73f9bc12SGunnar Mills```
125*73f9bc12SGunnar Millsdocker run --cap-add=sys_admin --rm=true \
126*73f9bc12SGunnar Mills  --privileged=true \
127*73f9bc12SGunnar Mills  -w "${WORKSPACE}" -v "${WORKSPACE}":"${WORKSPACE}" \
128*73f9bc12SGunnar Mills  -e "MAKEFLAGS=${MAKEFLAGS}" \
129*73f9bc12SGunnar Mills  -t ${DOCKER_IMG_NAME} \
130*73f9bc12SGunnar Mills  ${WORKSPACE}/${DBUS_UNIT_TEST_PY} -u ${UNIT_TEST} \ -f ${DBUS_SYS_CONFIG_FILE}
131*73f9bc12SGunnar Mills```
132*73f9bc12SGunnar Mills
133*73f9bc12SGunnar Millswith:
134*73f9bc12SGunnar Mills
135*73f9bc12SGunnar Mills```
136*73f9bc12SGunnar Millsdocker run --cap-add=sys_admin --rm=true \
137*73f9bc12SGunnar Mills  --privileged=true \
138*73f9bc12SGunnar Mills  -w "${WORKSPACE}" -v "${WORKSPACE}":"${WORKSPACE}" \
139*73f9bc12SGunnar Mills  -e "MAKEFLAGS=${MAKEFLAGS}" \
140*73f9bc12SGunnar Mills  -it ${DOCKER_IMG_NAME} /bin/bash
141*73f9bc12SGunnar Mills```
142*73f9bc12SGunnar Mills
143*73f9bc12SGunnar MillsWhen you rerun `run-unit-test-docker.sh` you will be dropped into an interactive
144*73f9bc12SGunnar Millssession. This is handy if you need to run gdb on a core dump.
145