-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Sertac Ozercan <sozercan@gmail.com>
- Loading branch information
Showing
12 changed files
with
617 additions
and
510 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,172 @@ | ||
--- | ||
title: Building from source | ||
--- | ||
|
||
In this section, we'll go over how to build packages from source with Dalec. | ||
|
||
To do this, we'll need a few things: | ||
|
||
1. A list of sources to pull from | ||
2. A build script to build the sources | ||
3. A list of artifacts to include in the package | ||
|
||
In this example, we'll build the `go-md2man` package and container from [`go-md2man`](https://github.com/cpuguy83/go-md2man) repo using `v2.0.3` tag in the repo. | ||
|
||
First, let's start with the contructing a [Dalec spec](spec.md) file. | ||
|
||
We define the metadata of the package in the spec. This includes the name, packager, vendor, license, website, and description of the package. | ||
|
||
```yaml | ||
# syntax=ghcr.io/azure/dalec/frontend:latest | ||
name: go-md2man | ||
version: 2.0.3 | ||
revision: "1" | ||
packager: Dalec Example | ||
vendor: Dalec Example | ||
license: MIT | ||
description: A tool to convert markdown into man pages (roff). | ||
website: https://github.com/cpuguy83/go-md2man | ||
``` | ||
In the next section, we define the sources that we will be pulling from. In this case, we are pulling from a git repository. | ||
One thing to note, in many build systems you will not have access to the Internet while building the package, and indeed that is the case with the `mariner2` target. As such, this build will fail because `go build` will try to download the go modules. For this reason, we added a `generate` section to the source to run `go mod download` in a docker image with the `src` source mounted and then extract the go modules from the resulting filesystem. | ||
|
||
```yaml | ||
sources: | ||
src: | ||
git: | ||
url: https://github.com/cpuguy83/go-md2man.git | ||
commit: "v2.0.3" | ||
generate: | ||
- gomod: {} | ||
``` | ||
|
||
In the next section, we define the dependencies that are needed to build the package. In this case, we need the `golang` dependency at the build time, and `openssl-libs` at runtime. Build dependencies are dependencies that are needed to build the package, while runtime dependencies are dependencies that are needed to run the package. | ||
|
||
```yaml | ||
dependencies: | ||
build: | ||
golang: | ||
runtime: | ||
openssl-libs: | ||
``` | ||
|
||
Now, let's define the build steps. In this case, we are building the `go-md2man` binary. | ||
|
||
```yaml | ||
build: | ||
env: | ||
CGO_ENABLED: "0" | ||
steps: | ||
- command: | | ||
cd src | ||
go build -o go-md2man . | ||
``` | ||
|
||
Next, we define the artifacts that we want to include in the package. In this case, we are including the `go-md2man` binary. | ||
|
||
```yaml | ||
artifacts: | ||
binaries: | ||
src/go-md2man: | ||
``` | ||
|
||
Image section defines the entrypoint and command for the image. In this case, we are setting the entrypoint to `go-md2man` and the command to `--help`. | ||
|
||
```yaml | ||
image: | ||
entrypoint: go-md2man | ||
cmd: --help | ||
``` | ||
|
||
Finally, we can add a test case to the spec file which helps ensure the package is assembled as expected. The following test will make sure `/usr/bin/go-md2man` is installed and has the expected permissions. These tests are automatically executed when building the container image. | ||
|
||
```yaml | ||
tests: | ||
- name: Check bin | ||
files: | ||
/usr/bin/go-md2man: | ||
permissions: 0755 | ||
``` | ||
|
||
Now, let's put it all together in a single file. | ||
|
||
```yaml | ||
# syntax=ghcr.io/azure/dalec/frontend:latest | ||
# syntax=ghcr.io/azure/dalec/frontend:latest | ||
name: go-md2man | ||
version: 2.0.3 | ||
revision: "1" | ||
packager: Dalec Example | ||
vendor: Dalec Example | ||
license: MIT | ||
description: A tool to convert markdown into man pages (roff). | ||
website: https://github.com/cpuguy83/go-md2man | ||
sources: | ||
src: | ||
generate: | ||
- gomod: {} | ||
git: | ||
url: https://github.com/cpuguy83/go-md2man.git | ||
commit: "v2.0.3" | ||
dependencies: | ||
build: | ||
golang: | ||
build: | ||
env: | ||
CGO_ENABLED: "0" | ||
steps: | ||
- command: | | ||
cd src | ||
go build -o go-md2man . | ||
artifacts: | ||
binaries: | ||
src/go-md2man: | ||
image: | ||
entrypoint: go-md2man | ||
cmd: --help | ||
tests: | ||
- name: Check bin | ||
files: | ||
/usr/bin/go-md2man: | ||
permissions: 0755 | ||
``` | ||
|
||
:::note | ||
Full example can be found at [examples/go-md2man.yml](https://github.com/Azure/dalec/blob/main/docs/examples/go-md2man.yml) | ||
::: | ||
|
||
Now that we have the spec file, we can build the package and container using `docker`. | ||
|
||
## Building using Docker | ||
|
||
In this section, we'll go over how to build packages and containers with Dalec. Other applicable Docker parameters will also apply to Dalec. | ||
|
||
Targets here are example. You can find more information about applicable targets in the [targets](targets.md) section. | ||
|
||
### Building an RPM package | ||
|
||
To build an RPM package only, we can use the following command: | ||
|
||
```shell | ||
docker build -t go-md2man:2.0.3 -f examples/go-md2man.yml --target=mariner2/rpm --output=_output . | ||
``` | ||
|
||
This will create `RPM` and `SRPM` directories in the `_output` directory with the built RPM and SRPM packages respectively. | ||
|
||
### Building a container | ||
|
||
To build a container, we can use the following command: | ||
|
||
```shell | ||
docker build -t go-md2man:2.0.3 -f examples/go-md2man.yml --target=mariner2, | ||
``` | ||
|
||
This will produce a container image named `go-md2man:2.0.3`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
--- | ||
title: Building with DALEC | ||
--- | ||
|
||
In this section, we'll go over how to build packages and containers with Dalec. | ||
|
||
To get started, you'll need to have [Docker](https://docs.docker.com/engine/install/) installed. | ||
|
||
## Creating a Dalec Spec | ||
|
||
The Dalec spec is a YAML file that describes the package to be built and any customizations to the output image. It includes package metadata like name, version, packager, and other things typically found in a system package. It also includes a list of build and runtime dependencies, how to build the project to be packaged, and what files are included in the package. | ||
|
||
For more information on the Dalec spec, see the [DALEC Specification](spec.md). | ||
|
||
## Building from source(s) | ||
|
||
Dalec can build packages and containers from source code repositories. This is done by specifying the source code repository and the build steps in the Dalec spec. The source code is checked out, built, and the resulting artifacts are included in the package. | ||
|
||
For more information on building from source, see [Building from source](build-source.md). | ||
|
||
## Virtual Packages | ||
|
||
In addition to building a traditional package that installs binaries and other files you can also create a "virtual" package, which is a package that references other packages but doesn't install any files itself. This is useful for creating a package that is just a collection of dependencies. | ||
|
||
For more information on virtual packages, see [Virtual Packages](virtual-packages.md). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.