Skip to content

Commit

Permalink
Merge pull request #193 from darkmuggle/master
Browse files Browse the repository at this point in the history
Build Enhancements: added Makefile and fixed unbound variable
  • Loading branch information
openshift-merge-robot committed Dec 5, 2018
2 parents d9b254f + 512f5b1 commit 20c1299
Show file tree
Hide file tree
Showing 2 changed files with 97 additions and 23 deletions.
83 changes: 83 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
# vim: noexpandtab ts=8
my_p=$(shell pwd -P)
export GOPATH=$(shell echo $${GOPATH:-$$HOME/go})

.PHONY: clean test verify update
# Remove build artifaces
# Example:
# make clean
#
clean:
@rm -rf $(my_p)/_output

# Build machine configs. Intended to be called via another target.
# Example:
# make _build-setup-etcd
_build-%:
WHAT=$* $(my_p)/hack/build-go.sh

# Build image for a component. Intended to be called via another target.
# Example:
# make _image-machine-config-daemon
_image-%:
@which podman 2> /dev/null &>1 || { echo "podman must be installed to build an image"; exit 1; }
WHAT=$* $(my_p)/hack/build-image.sh

# Run unit tests
# Example:
# make test
test:
cd $(my_p) && go test -v ./...

# Run the code generation tasks.
# Example:
# make update
update:
$(my_p)/hack/update-codegen.sh

# Run verification steps
# Example:
# make verify
verify: test machine-configs
$(my_p)/hack/verify-style.sh
$(my_p)/hack/verify-codegen.sh

# Template for defining build targets for binaries.
define target_template =
.PHONY: $(1)
$(1): _build-$(1)

mc += $(1)
endef

# Create a target for each command defined in `cmd` except for common.
$(foreach P, $(patsubst cmd/%, %, $(shell find cmd -maxdepth 1 -mindepth 1 -type d -not -path cmd/common)), $(eval $(call target_template,$(P))))

# Template for image builds.
define image_template =
.PHONY: image-$(1)
image-$(1): _image-$(1) _build-$(1)

imc += image-$(1)
endef

# Call 'image_template' for each Dockerfile found.
$(foreach D, $(patsubst Dockerfile.%,%, $(wildcard Dockerfile*)), $(eval $(call image_template,$(D))))


.PHONY: machine-configs images images.rhel7

# Build all machine-configs:
# Example:
# make machine-configs
machine-configs: $(mc)

# Build all images:
# Example:
# make images
images: $(imc)

# Build all images for rhel7
# Example:
# make images.rhel7
images.rhel7: $(imc7)
37 changes: 14 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,23 @@
# machine-config-operator

## machine-config-operator
- Build: `WHAT=machine-config-operator ./hack/build-go.sh`
## Generic building

## machine-config-server
You can either use the Makefile or the `hack/build-go.sh` script directory to build the targets. When using `hack/build-go.sh` you will need to run it via `WHAT=<TARGET> hack/build-go.sh`

### machine-config-operator
- Build: `make machine-config-operator`

### machine-config-server
- [Design doc](docs/MachineConfigServer.md)
- Build: `WHAT=machine-config-server ./hack/build-go.sh`
- Build: `make machine-config-server`

## machine-config-daemon
### machine-config-daemon
- [Design doc](docs/MachineConfigDaemon.md)
- Build: `WHAT=machine-config-daemon ./hack/build-go.sh`
- Build: `make machine-config-daemon`

## machine-config-controller
### machine-config-controller
- [Design doc](docs/MachineConfigController.md)
- `WHAT=machine-config-controller ./hack/build-go.sh`
- Build: `make machine-config-controller`

## Tests
Tests can be executed on a per package basis with `go test` like so:
Expand All @@ -22,22 +26,9 @@ Tests can be executed on a per package basis with `go test` like so:

All tests can be executed with:

`go test -v ./...`
`make test`

## Building Images
**NOTE**: To build images you will need [`podman`](https://github.com/containers/libpod/) installed.

Images can be built locally via the `hack/build-image.sh` script. This script uses the
`WHAT` variable similarly to the `hack/build-go.sh` script.

```console
$ ./hack/build-image.sh
ERROR: Note: Building unprivileged may fail due to permissions
ERROR: WHAT must be set to one of the following:
ERROR: - all
ERROR: - machine-config-controller
ERROR: - machine-config-daemon
ERROR: - machine-config-operator
$ WHAT=machine-config-daemon ./hack/build-image.sh
[...]
```
Images can be built for the corresponding Dockerfiles via `make image-<TOPIC>` where `<TOPIC>` is the suffix after the first dot. For example `Dockerfile.setup-etcd-environment.rhel7` would be `make image-setup-etcd-environment.rhel7`.

0 comments on commit 20c1299

Please sign in to comment.