Skip to content

Commit fc4f303

Browse files
authored
Merge pull request #631 from james-crowley/contrib_examples
Added a contrib folder which contains Docker examples
2 parents 816efbf + 5545c22 commit fc4f303

14 files changed

+702
-0
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,9 @@ Be aware that this variables may be subject to change again in future versions.
184184
* [kubic](https://github.com/kubic-project)
185185
* [kubic-terraform-kvm](https://github.com/kubic-project/kubic-terraform-kvm) Kubic Terraform script using KVM/libvirt
186186

187+
* [Community Driven Docker Examples](contrib/)
188+
Docker examples showing how to use the Libvirt Provider
189+
187190
* [Openshift 4 Installer](https://github.com/openshift/installer)
188191
The Openshift 4 Installer uses Terraform for cluster orchestration and relies on terroform-provider-libvirt for
189192
libvirt platform.
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
# Set to linux or name of OS
2+
ARG GO_OS
3+
4+
# Set to arch name of your system
5+
ARG GO_ARCH
6+
7+
# Terraform Version
8+
ARG TERRAFORM_VERSION=0.12.0
9+
10+
# Provider Version
11+
ARG VERSION
12+
13+
# Grab the Terraform binary
14+
FROM hashicorp/terraform:$TERRAFORM_VERSION AS terraform
15+
16+
# Building Libvirt Plugin Docker
17+
FROM golang:alpine AS libvirt
18+
19+
ARG VERSION
20+
ENV VERSION=$VERSION
21+
22+
# Install Needed Packages. Libc-dev installs musl-dev
23+
RUN apk update \
24+
&& apk upgrade \
25+
&& apk add --no-cache git make gcc pkgconfig libvirt-dev libc-dev
26+
27+
# Pull Go lint for building
28+
RUN go get -u golang.org/x/lint/golint
29+
30+
# Make directory
31+
RUN mkdir -p $GOPATH/src/github.com/dmacvicar/
32+
33+
# Set Work Directory for Clone
34+
WORKDIR $GOPATH/src/github.com/dmacvicar/
35+
36+
# Clone Project
37+
RUN git clone https://github.com/dmacvicar/terraform-provider-libvirt.git
38+
39+
# Set Workdir for bin build
40+
WORKDIR $GOPATH/src/github.com/dmacvicar/terraform-provider-libvirt
41+
42+
# Checkout Version and download go dependencies
43+
RUN git checkout $VERSION && env GO111MODULE=on go mod download
44+
45+
# Build and move the Binary
46+
RUN make build && mv terraform-provider-libvirt $GOPATH/bin/
47+
48+
# Base Image
49+
FROM alpine:latest
50+
51+
ARG GO_OS
52+
ENV GO_OS=$GO_OS
53+
ARG GO_ARCH
54+
ENV GO_ARCH=$GO_ARCH
55+
56+
# Set working directory
57+
WORKDIR /root/
58+
59+
# Make Directory for Provider Binaries
60+
RUN mkdir -p /root/.terraform.d/plugins/${GO_OS}_${GO_ARCH}/
61+
62+
# Copy binaries from containers
63+
COPY --from=terraform /bin/terraform /bin/
64+
COPY --from=libvirt /go/bin/terraform-provider-libvirt /root/.terraform.d/plugins/${GO_OS}_${GO_ARCH}/
65+
66+
# Install Dependencies
67+
# Libvirt is needed to run the provider. libxslt needed to use XML/XSLT. cdrkit needed to use cloud init images
68+
# openssh-client to talk to remote libvirt server
69+
RUN apk update \
70+
&& apk upgrade \
71+
&& apk add --no-cache libvirt gcc libxslt cdrkit openssh-client
72+
73+
# Copy Terraform Files
74+
# COPY libvirt.tf /root/
75+
76+
# Terraform commands
77+
# RUN terraform init
78+
79+
ENTRYPOINT /bin/ash
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# Set to linux or name of OS
2+
ARG GO_OS
3+
4+
# Set to arch name of your system
5+
ARG GO_ARCH
6+
7+
# Terraform Version
8+
ARG TERRAFORM_VERSION=0.12.0
9+
10+
# Grab the Terraform binary
11+
FROM hashicorp/terraform:$TERRAFORM_VERSION AS terraform
12+
13+
# Grab the Terraform Libvirt Provider binary
14+
FROM provider-libvirt:v0.5.2-musl AS libvirt
15+
16+
# Base Image
17+
FROM alpine:latest
18+
19+
ARG GO_OS
20+
ENV GO_OS=$GO_OS
21+
ARG GO_ARCH
22+
ENV GO_ARCH=$GO_ARCH
23+
24+
# Set working directory
25+
WORKDIR /root/
26+
27+
# Make Directory for Provider Binaries
28+
RUN mkdir -p /root/.terraform.d/plugins/${GO_OS}_${GO_ARCH}/
29+
30+
# Copy binaries from containers
31+
COPY --from=terraform /bin/terraform /bin/
32+
COPY --from=libvirt /go/bin/terraform-provider-libvirt /root/.terraform.d/plugins/${GO_OS}_${GO_ARCH}/
33+
34+
# Install Dependencies
35+
# Libvirt is needed to run the provider. libxslt needed to use XML/XSLT. cdrkit needed to use cloud init images
36+
# openssh-client to talk to remote libvirt server
37+
RUN apk update \
38+
&& apk upgrade \
39+
&& apk add --no-cache libvirt gcc libxslt cdrkit openssh-client
40+
41+
# Copy Terraform Files
42+
# COPY libvirt.tf /root/
43+
44+
# Terraform commands
45+
# RUN terraform init
46+
47+
ENTRYPOINT /bin/ash

contrib/Alpine/README.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Alpine Container
2+
This container is built from the `Alpine` distribution. This container is meant to serve as a slim down minimalistic
3+
container.
4+
5+
**NOTE**: If pulling from the `build` containers, make sure to pull from the `musl` container. Alpine uses `musl` instead
6+
of `glibc`.
7+
8+
9+
## All-in-One Container Build Example
10+
```console
11+
docker build -f Dockerfile_all_in_one -t terraform:development-alpine . --build-arg VERSION=v0.5.2 --build-arg GO_OS=linux --build-arg GO_ARCH=amd64 --build-arg TERRAFORM_VERSION=0.11.14
12+
```
13+
14+
15+
## Build-Dependent Container Build Example
16+
Build appropriate `Build` container, in this case it would be `Dockerfile_musl`:
17+
18+
```cosnole
19+
docker build -f Dockerfile_musl -t provider-libvirt:v0.5.2-musl . --build-arg VERSION=v0.5.2
20+
```
21+
22+
Now build the main container:
23+
```console
24+
docker build -f Dockerfile_build_dependent -t terraform:development-alpine . --build-arg GO_OS=linux --build-arg GO_ARCH=amd64 --build-arg TERRAFORM_VERSION=0.11.14
25+
```
26+

contrib/Build/Dockerfile_glibc

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Building Libvirt Plugin Docker
2+
FROM golang:stretch
3+
4+
ARG VERSION
5+
ENV VERSION=$VERSION
6+
7+
# Install Needed Packages
8+
RUN apt-get update \
9+
&& apt-get upgrade -y \
10+
&& apt-get install \
11+
-y --no-install-recommends \
12+
git make pkg-config gcc libc-dev libvirt-dev \
13+
&& rm -rf /var/lib/apt/lists/*
14+
15+
# Pull Go lint for building
16+
RUN go get -u golang.org/x/lint/golint
17+
18+
# Make directory
19+
RUN mkdir -p $GOPATH/src/github.com/dmacvicar/
20+
21+
# Set Work Directory for Clone
22+
WORKDIR $GOPATH/src/github.com/dmacvicar/
23+
24+
# Clone Project
25+
RUN git clone https://github.com/dmacvicar/terraform-provider-libvirt.git
26+
27+
# Set Workdir for bin build
28+
WORKDIR $GOPATH/src/github.com/dmacvicar/terraform-provider-libvirt
29+
30+
# Checkout Version and download go dependencies
31+
RUN git checkout $VERSION && env GO111MODULE=on go mod download
32+
33+
# Build and move the Binary
34+
RUN make build && mv terraform-provider-libvirt $GOPATH/bin/

contrib/Build/Dockerfile_musl

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Building Libvirt Plugin Docker
2+
FROM golang:alpine
3+
4+
ARG VERSION
5+
ENV VERSION=$VERSION
6+
7+
# Install Needed Packages. Libc-dev installs musl-dev
8+
RUN apk update \
9+
&& apk upgrade \
10+
&& apk add --no-cache git make gcc pkgconfig libvirt-dev libc-dev
11+
12+
# Pull Go lint for building
13+
RUN go get -u golang.org/x/lint/golint
14+
15+
# Make directory
16+
RUN mkdir -p $GOPATH/src/github.com/dmacvicar/
17+
18+
# Set Work Directory for Clone
19+
WORKDIR $GOPATH/src/github.com/dmacvicar/
20+
21+
# Clone Project
22+
RUN git clone https://github.com/dmacvicar/terraform-provider-libvirt.git
23+
24+
# Set Workdir for bin build
25+
WORKDIR $GOPATH/src/github.com/dmacvicar/terraform-provider-libvirt
26+
27+
# Checkout Version and download go dependencies
28+
RUN git checkout $VERSION && env GO111MODULE=on go mod download
29+
30+
# Build and move the Binary
31+
RUN make build && mv terraform-provider-libvirt $GOPATH/bin/

contrib/Build/README.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Build Containers
2+
These containers build the terraform libvirt provider. There are two Dockerfiles due to the fact that some linux
3+
systems use `musl` while others use `glibc`. These are just two different implementations of the `libc`, each having
4+
their benefits. "Most" systems use `glibc` but there are a couple linux distributions like `Alpine` that use `musl`. When
5+
in doubt, use `glibc`.
6+
7+
These containers will be mostly used as one of the stages in the multi-stage Dockefiles you'll find here. They also have
8+
the benefit of storing the binary in the container, thus you could use a `docker copy` to grab the binary and use it
9+
on your local system.
10+
11+
## General Usage
12+
As stated before in the general [README](../), these containers have build arguments.
13+
14+
To build the two containers use these commands:
15+
16+
```console
17+
docker build -f Dockerfile_glibc -t provider-libvirt:v0.5.2-glibc . --build-arg VERSION=v0.5.2
18+
```
19+
20+
Which would build the `glibc` version with the code of the `v0.5.2` branch.
21+
22+
```console
23+
docker build -f Dockerfile_musl -t provider-libvirt:master-musl . --build-arg VERSION=master
24+
```
25+
26+
Which would build the `musl` version with the code of the `master` branch.
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
# Set to linux or name of OS
2+
ARG GO_OS
3+
4+
# Set to arch name of your system
5+
ARG GO_ARCH
6+
7+
# Terraform Version
8+
ARG TERRAFORM_VERSION=0.12.0
9+
10+
# Provider Version
11+
ARG VERSION
12+
13+
# Grab the Terraform binary
14+
FROM hashicorp/terraform:$TERRAFORM_VERSION AS terraform
15+
16+
# Building Libvirt Plugin Docker
17+
FROM golang:stretch as libvirt
18+
19+
ARG VERSION
20+
ENV VERSION=$VERSION
21+
22+
# Install Needed Packages
23+
RUN apt-get update \
24+
&& apt-get upgrade -y \
25+
&& apt-get install \
26+
-y --no-install-recommends \
27+
git make pkg-config gcc libc-dev libvirt-dev \
28+
&& rm -rf /var/lib/apt/lists/*
29+
30+
# Pull Go lint for building
31+
RUN go get -u golang.org/x/lint/golint
32+
33+
# Make directory
34+
RUN mkdir -p $GOPATH/src/github.com/dmacvicar/
35+
36+
# Set Work Directory for Clone
37+
WORKDIR $GOPATH/src/github.com/dmacvicar/
38+
39+
# Clone Project
40+
RUN git clone https://github.com/dmacvicar/terraform-provider-libvirt.git
41+
42+
# Set Workdir for bin build
43+
WORKDIR $GOPATH/src/github.com/dmacvicar/terraform-provider-libvirt
44+
45+
# Checkout Version and download go dependencies
46+
RUN git checkout $VERSION && env GO111MODULE=on go mod download
47+
48+
# Build and move the Binary
49+
RUN make build && mv terraform-provider-libvirt $GOPATH/bin/
50+
51+
# Base Image
52+
FROM ubuntu:18.04
53+
54+
ARG GO_OS
55+
ENV GO_OS=$GO_OS
56+
ARG GO_ARCH
57+
ENV GO_ARCH=$GO_ARCH
58+
59+
# Set working directory
60+
WORKDIR /root/
61+
62+
# Make Directory for Provider Binaries
63+
RUN mkdir -p /root/.terraform.d/plugins/${GO_OS}_${GO_ARCH}/
64+
65+
# Copy binaries from containers
66+
COPY --from=terraform /bin/terraform /bin/
67+
COPY --from=libvirt /go/bin/terraform-provider-libvirt /root/.terraform.d/plugins/${GO_OS}_${GO_ARCH}/
68+
69+
# Install Dependencies
70+
# libvirt0 is needed to run the provider. xsltproc needed to use XML/XSLT. mkisofs needed to use cloud init images
71+
# ca-certificates to avoid terraform init 509 error. openssh-client to talk to remote libvirt server
72+
RUN apt-get update \
73+
&& apt-get upgrade -y \
74+
&& apt-get install \
75+
-y --no-install-recommends \
76+
libvirt0 xsltproc mkisofs ca-certificates openssh-client \
77+
&& rm -rf /var/lib/apt/lists/*
78+
79+
# Copy Terraform Files
80+
# COPY libvirt.tf /root/
81+
82+
# Terraform commands
83+
# RUN terraform init
84+
85+
ENTRYPOINT /bin/bash

0 commit comments

Comments
 (0)