Skip to content

Commit 7f2783b

Browse files
JAORMXjhrozek
authored andcommitted
Add Dockerfile and targets to build and run the container
This adds the `image`, `push` and `runc` targets, which are for building, pushinng and running the container.
1 parent c4dda54 commit 7f2783b

File tree

3 files changed

+74
-0
lines changed

3 files changed

+74
-0
lines changed

Diff for: .dockerignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
bin/

Diff for: Dockerfile

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# Copyright © 2020 Red Hat, Inc.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
FROM registry.centos.org/centos:8 AS build
16+
USER root
17+
WORKDIR /work
18+
19+
# Speed up build by leveraging docker layer caching
20+
COPY go.mod go.sum vendor/ ./
21+
RUN mkdir -p bin
22+
23+
RUN dnf install -y --disableplugin=subscription-manager \
24+
--enablerepo=powertools \
25+
golang make libsemanage-devel
26+
27+
ADD . /work
28+
29+
RUN make
30+
31+
FROM registry.centos.org/centos:8 AS build
32+
# TODO(jaosorior): Switch to UBI once we use static linking
33+
#FROM registry.access.redhat.com/ubi8/ubi-minimal:latest
34+
35+
# TODO(jaosorior): See if we can run this without root
36+
USER root
37+
38+
LABEL name="selinuxd" \
39+
description="selinuxd is a daemon that listens for files in /etc/selinux.d/ and installs the relevant policies."
40+
41+
# TODO(jaosorior): Remove once we use static linking
42+
RUN dnf install -y --disableplugin=subscription-manager \
43+
--enablerepo=powertools \
44+
policycoreutils
45+
46+
COPY --from=build /work/bin/selinuxdctl /usr/bin/
47+
48+
ENTRYPOINT ["/usr/bin/selinuxdctl"]

Diff for: Makefile

+25
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,14 @@ ifeq ($(OS_NAME), Darwin)
1313
endif
1414
GOLANGCI_LINT_URL=https://github.com/golangci/golangci-lint/releases/download/v$(GOLANGCI_LINT_VERSION)/golangci-lint-$(GOLANGCI_LINT_VERSION)-$(GOLANGCI_LINT_OS)-amd64.tar.gz
1515

16+
CONTAINTER_RUNTIME?=podman
17+
18+
IMAGE_NAME=selinuxd
19+
IMAGE_TAG=latest
20+
21+
IMAGE_REF=$(IMAGE_NAME):$(IMAGE_TAG)
22+
23+
IMAGE_REPO?=quay.io/jaosorior/$(IMAGE_REF)
1624

1725
# Targets
1826

@@ -33,6 +41,15 @@ test:
3341
run: $(BIN) $(POLICYDIR)
3442
sudo $(BIN) daemon
3543

44+
.PHONY: runc
45+
runc: image $(POLICYDIR)
46+
sudo $(CONTAINTER_RUNTIME) run -ti \
47+
--privileged \
48+
-v /sys/fs/selinux:/sys/fs/selinux \
49+
-v /var/lib/selinux:/var/lib/selinux \
50+
-v /etc/selinux.d:/etc/selinux.d \
51+
$(IMAGE_REPO) daemon
52+
3653
$(BINDIR):
3754
mkdir -p $(BINDIR)
3855

@@ -60,3 +77,11 @@ $(GOPATH)/bin/golangci-lint:
6077
(echo "curl returned $$? trying to fetch golangci-lint. please install golangci-lint and try again"; exit 1); \
6178
GOLANGCI_LINT_CACHE=/tmp/golangci-cache $(GOPATH)/bin/golangci-lint version
6279
GOLANGCI_LINT_CACHE=/tmp/golangci-cache $(GOPATH)/bin/golangci-lint linters
80+
81+
.PHONY: image
82+
image:
83+
$(CONTAINTER_RUNTIME) build -t $(IMAGE_REPO) .
84+
85+
.PHONY: push
86+
push:
87+
$(CONTAINTER_RUNTIME) push $(IMAGE_REPO)

0 commit comments

Comments
 (0)