-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #18 from tuxerrante/dev
#18 - Manage custom labels, validate profile content, manage SIGTERM
- Loading branch information
Showing
19 changed files
with
258 additions
and
77 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 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 |
---|---|---|
@@ -1,44 +1,44 @@ | ||
# --- build stage | ||
FROM golang:1.20 AS builder | ||
|
||
WORKDIR /builder/app | ||
COPY go/src/app/ . | ||
COPY go/src/tests/ /builder/tests/ | ||
COPY go.mod . | ||
|
||
RUN go get -d -v . &&\ | ||
go build -v -o /go/bin/app . | ||
|
||
RUN go test -v -coverprofile=coverage.out -covermode=atomic | ||
# go tool cover -func=coverage.out | ||
|
||
|
||
# --- Publish test coverage results | ||
FROM scratch as test-coverage | ||
COPY --from=builder /builder/app/coverage.out . | ||
|
||
|
||
# --- Production image | ||
FROM ubuntu:latest | ||
LABEL Name=kapparmor | ||
LABEL Author="Affinito Alessandro" | ||
|
||
WORKDIR /app | ||
|
||
RUN apt-get update &&\ | ||
apt-get upgrade -y &&\ | ||
apt-get install --no-install-recommends --yes apparmor apparmor-utils &&\ | ||
rm -rf /var/lib/apt/lists/* &&\ | ||
mkdir --parent --verbose /etc/apparmor.d/custom | ||
|
||
COPY --from=builder /go/bin/app /app/ | ||
COPY ./charts/kapparmor/profiles /app/profiles/ | ||
|
||
ARG PROFILES_DIR | ||
ARG POLL_TIME | ||
|
||
ENV PROFILES_DIR=$PROFILES_DIR | ||
ENV POLL_TIME=$POLL_TIME | ||
|
||
USER root | ||
CMD ./app | ||
# --- build stage | ||
FROM golang:1.20 AS builder | ||
|
||
WORKDIR /builder/app | ||
COPY go/src/app/ . | ||
COPY go/src/tests/ /builder/tests/ | ||
COPY go.mod . | ||
|
||
RUN go get -d -v . &&\ | ||
go build -v -o /go/bin/app . | ||
|
||
RUN go test -v -coverprofile=coverage.out -covermode=atomic ./... | ||
# go tool cover -func=coverage.out | ||
|
||
|
||
# --- Publish test coverage results | ||
FROM scratch as test-coverage | ||
COPY --from=builder /builder/app/coverage.out . | ||
|
||
|
||
# --- Production image | ||
FROM ubuntu:latest | ||
LABEL Name=kapparmor | ||
LABEL Author="Affinito Alessandro" | ||
|
||
WORKDIR /app | ||
|
||
RUN apt-get update &&\ | ||
apt-get upgrade -y &&\ | ||
apt-get install --no-install-recommends --yes apparmor apparmor-utils &&\ | ||
rm -rf /var/lib/apt/lists/* &&\ | ||
mkdir --parent --verbose /etc/apparmor.d/custom | ||
|
||
COPY --from=builder /go/bin/app /app/ | ||
COPY ./charts/kapparmor/profiles /app/profiles/ | ||
|
||
ARG PROFILES_DIR | ||
ARG POLL_TIME | ||
|
||
ENV PROFILES_DIR=$PROFILES_DIR | ||
ENV POLL_TIME=$POLL_TIME | ||
|
||
USER root | ||
ENTRYPOINT ["./app"] |
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
Empty file.
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,34 @@ | ||
#!/bin/bash | ||
set -e | ||
|
||
. ./build/build-app.sh | ||
. ./config/secrets | ||
|
||
echo $GHCR_TOKEN | docker login -u "$(git config user.email)" --password-stdin ghcr.io | ||
docker push ghcr.io/tuxerrante/kapparmor:${APP_VERSION}_dev | ||
|
||
# Install the chart from the local directory | ||
helm upgrade kapparmor --install \ | ||
--atomic \ | ||
--debug \ | ||
--set image.tag=${APP_VERSION}_dev \ | ||
--set image.pullPolicy=Always \ | ||
--dry-run \ | ||
charts/kapparmor | ||
|
||
echo | ||
echo "> Is the previous result the expected one?" | ||
echo "> Current K8S context:" "$(kubectl config current-context)" | ||
read -r -p "> Are you sure? [Y/n] " response | ||
if [[ "$response" =~ ^([yY][eE][sS]|[yY])$ ]]; then | ||
helm upgrade kapparmor --install \ | ||
--atomic \ | ||
--timeout 120s \ | ||
--debug \ | ||
--set image.tag=${APP_VERSION}_dev \ | ||
--set image.pullPolicy=Always \ | ||
charts/kapparmor | ||
else | ||
echo " Bye." | ||
echo | ||
fi |
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,43 @@ | ||
#!/bin/bash | ||
source ./config/config | ||
|
||
# --- Validate App and Chart version | ||
YML_CHART_VERSION="$(grep "version: [\"0-9\.]\+" charts/kapparmor/Chart.yaml |cut -d'"' -f2)" | ||
YML_APP_VERSION="$(grep "appVersion: [\"0-9\.]\+" charts/kapparmor/Chart.yaml |cut -d'"' -f2)" | ||
|
||
if [[ $APP_VERSION != $YML_APP_VERSION ]]; then | ||
echo "The APP version declared in the Chart is different from the one in the config!" | ||
exit 1 | ||
elif [[ $CHART_VERSION != $YML_CHART_VERSION ]]; then | ||
echo "The APP version declared in the Chart is different from the one in the config!" | ||
exit 1 | ||
fi | ||
|
||
# Clean old images | ||
echo "> Removing old and dangling old images..." | ||
docker rmi "$(docker images --filter "reference=ghcr.io/tuxerrante/kapparmor" -q --no-trunc )" | ||
|
||
# go build -o ./.go/bin ./... | ||
# go test -v -coverprofile=coverage.out -covermode=atomic ./go/src/app/... | ||
if [[ ! -f ".go/bin/golangci-lint" ]]; then | ||
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b ./.go/bin | ||
fi | ||
echo "> Linting..." | ||
./.go/bin/golangci-lint run | ||
|
||
echo "> Scanning for suspicious constructs..." | ||
go vet go/... | ||
|
||
echo "> Creating test output..." | ||
docker build --target test-coverage --tag "ghcr.io/tuxerrante/kapparmor:${APP_VERSION}_dev" . | ||
|
||
#### To run it look into docs/testing.md | ||
echo "> Building container image..." | ||
docker build --tag "ghcr.io/tuxerrante/kapparmor:${APP_VERSION}_dev" \ | ||
--no-cache \ | ||
--build-arg POLL_TIME=30 \ | ||
--build-arg PROFILES_DIR=/app/profiles \ | ||
-f Dockerfile \ | ||
. | ||
|
||
# docker run --rm -it --privileged --mount type=bind,source='/sys/kernel/security',target='/sys/kernel/security' --mount type=bind,source='/etc',target='/etc' --name kapparmor ghcr.io/tuxerrante/kapparmor:${APP_VERSION}_dev |
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
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
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
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,2 @@ | ||
APP_VERSION=0.1.5 | ||
CHART_VERSION=0.1.5 |
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
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
Oops, something went wrong.