Skip to content
This repository was archived by the owner on May 24, 2023. It is now read-only.

Commit b6f3902

Browse files
authored
Update Dockerfile and CI (#191)
1 parent 44912fc commit b6f3902

File tree

4 files changed

+41
-95
lines changed

4 files changed

+41
-95
lines changed

.github/workflows/ci.yml

+28-46
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ on:
88
- 'docs/**'
99
- 'examples/**'
1010
- '**.md'
11+
tags:
12+
- 'v[0-9]+.[0-9]+.[0-9]+'
1113
pull_request:
1214
branches:
1315
- master
@@ -19,9 +21,6 @@ on:
1921
- 'docs/**'
2022
- 'examples/**'
2123
- '**.md'
22-
create:
23-
tags:
24-
- 'v[0-9]+.[0-9]+.[0-9]+*'
2524

2625
env:
2726
DOCKER_BUILDKIT: 1
@@ -38,7 +37,6 @@ jobs:
3837
outputs:
3938
sha_short: ${{ steps.vars.outputs.sha }}
4039
go_version: ${{ steps.vars.outputs.go_version }}
41-
git_tag: ${{ steps.vars.outputs.git_tag }}
4240
repo_name: ${{ steps.vars.outputs.repo }}
4341
steps:
4442
- name: Checkout Repository
@@ -48,7 +46,6 @@ jobs:
4846
run: |
4947
echo "::set-output name=sha::$(echo ${GITHUB_SHA} | cut -c1-7)"
5048
echo "::set-output name=go_version::$(grep "go 1." go.mod | cut -d " " -f 2)"
51-
echo "::set-output name=git_tag::$(echo ${GITHUB_REF/refs\/tags\//} | tr -d v)"
5249
echo "::set-output name=repo::$(echo ${GITHUB_REPOSITORY} | cut -d '/' -f 2)"
5350
5451
binary:
@@ -96,23 +93,43 @@ jobs:
9693
with:
9794
path: ${{ github.workspace }}/bin/manager
9895
key: nginx-ingress-operator-${{ github.run_id }}-${{ github.run_number }}
96+
- name: DockerHub Login
97+
uses: docker/login-action@v1
98+
with:
99+
username: ${{ secrets.DOCKER_USERNAME }}
100+
password: ${{ secrets.DOCKER_PASSWORD }}
101+
if: github.event_name != 'pull_request'
99102
- name: Docker Buildx
100103
uses: docker/setup-buildx-action@v1
104+
- name: Docker meta
105+
id: meta
106+
uses: docker/metadata-action@v3
107+
with:
108+
images: |
109+
nginx/nginx-ingress-operator
110+
tags: |
111+
type=edge
112+
type=ref,event=pr
113+
type=semver,pattern={{version}}
114+
labels: |
115+
org.opencontainers.image.documentation=https://docs.nginx.com/nginx-ingress-controller
116+
org.opencontainers.image.vendor=NGINX Inc <[email protected]>
101117
- name: Build Image
102118
uses: docker/build-push-action@v2
103119
with:
104120
context: '.'
105121
cache-from: type=gha
106122
cache-to: type=gha,mode=max
107-
tags: nginx/nginx-ingress-operator:${{ github.sha }}
108-
push: false
123+
tags: ${{ steps.meta.outputs.tags }}
124+
labels: ${{ steps.meta.outputs.labels }}
125+
load: ${{ github.event_name == 'pull_request' }}
126+
push: ${{ github.event_name != 'pull_request' }}
109127
pull: true
110-
load: true
111128
- name: Run Trivy vulnerability scanner
112129
uses: aquasecurity/[email protected]
113130
continue-on-error: true
114131
with:
115-
image-ref: nginx/nginx-ingress-operator:${{ github.sha }}
132+
image-ref: nginx/nginx-ingress-operator:${{ steps.meta.outputs.version }}
116133
format: 'template'
117134
template: '@/contrib/sarif.tpl'
118135
output: 'trivy-results.sarif'
@@ -121,7 +138,7 @@ jobs:
121138
uses: github/codeql-action/upload-sarif@v1
122139
continue-on-error: true
123140
with:
124-
sarif_file: 'trivy-result.sarif'
141+
sarif_file: 'trivy-results.sarif'
125142
- name: Upload Scan Results
126143
uses: actions/upload-artifact@v2
127144
continue-on-error: true
@@ -130,46 +147,11 @@ jobs:
130147
path: 'trivy-results.sarif'
131148
if: always()
132149

133-
release-docker:
134-
name: Release Image
135-
runs-on: ubuntu-20.04
136-
needs: [vars, build, unit-tests]
137-
if:
138-
github.repository == 'nginxinc/nginx-ingress-operator' &&
139-
github.event_name == 'create' &&
140-
contains(github.ref, 'refs/tags/')
141-
steps:
142-
- name: Checkout Repository
143-
uses: actions/checkout@v2
144-
- name: Fetch Cached Artifacts
145-
uses: actions/cache@v2
146-
with:
147-
path: ${{ github.workspace }}/build/_output/bin/nginx-ingress-operator
148-
key: nginx-ingress-operator-${{ github.run_id }}-${{ github.run_number }}
149-
- name: Docker Buildx
150-
uses: docker/setup-buildx-action@v1
151-
- name: DockerHub Login
152-
uses: docker/login-action@v1
153-
with:
154-
username: ${{ secrets.DOCKER_USERNAME }}
155-
password: ${{ secrets.DOCKER_PASSWORD }}
156-
- name: Push to Dockerhub
157-
uses: docker/build-push-action@v2
158-
with:
159-
file: Dockerfile
160-
context: '.'
161-
cache-from: type=gha
162-
cache-to: type=gha,mode=max
163-
tags: |
164-
nginx/nginx-ingress-operator:latest
165-
nginx/nginx-ingress-operator:${{ needs.vars.outputs.git_tag }}
166-
push: true
167-
pull: true
168150

169151
notify:
170152
name: Notify
171153
runs-on: ubuntu-20.04
172-
needs: [vars, release-docker]
154+
needs: [vars, build]
173155
if: always() && github.ref == 'refs/heads/master'
174156
steps:
175157
- name: Workflow Status

Dockerfile

+13-5
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,20 @@ COPY controllers/ controllers/
1818
# Build
1919
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags "-s -w -X main.version=${VERSION}" -a -o manager main.go
2020

21-
# Use distroless as minimal base image to package the manager binary
22-
# Refer to https://github.com/GoogleContainerTools/distroless for more details
23-
FROM gcr.io/distroless/static:nonroot
21+
FROM registry.access.redhat.com/ubi8/ubi-minimal:latest
22+
ARG VERSION
2423
WORKDIR /
25-
COPY --from=builder --chown=65532:65532 /workspace/manager .
24+
COPY --from=builder /workspace/manager .
2625
COPY config/crd/kic ./config/crd/kic
27-
USER 65532:65532
26+
COPY LICENSE /licenses/
27+
28+
LABEL name="NGINX Ingress Operator" \
29+
vendor="NGINX Inc <[email protected]" \
30+
version="v${VERSION}" \
31+
release="1" \
32+
summary="The NGINX Ingress Operator is a Kubernetes/OpenShift component which deploys and manages one or more NGINX/NGINX Plus Ingress Controllers" \
33+
description="The NGINX Ingress Operator is a Kubernetes/OpenShift component which deploys and manages one or more NGINX/NGINX Plus Ingress Controllers"
2834

2935
ENTRYPOINT ["/manager"]
36+
37+
USER 1001

Makefile

-7
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,7 @@ IMG ?= $(IMAGE_TAG_BASE):$(VERSION)
4141
# ENVTEST_K8S_VERSION refers to the version of kubebuilder assets to be downloaded by envtest binary.
4242
ENVTEST_K8S_VERSION = 1.22
4343

44-
# Change DOCKERFILE tp openshift.Dockerfile to build Openshift image
4544
DOCKERFILE ?= Dockerfile
46-
RH_RBAC_IMAGE ?= registry.redhat.io/openshift4/ose-kube-rbac-proxy:v4.7
4745

4846
# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
4947
ifeq (,$(shell go env GOBIN))
@@ -125,11 +123,6 @@ deploy: manifests kustomize ## Deploy controller to the K8s cluster specified in
125123
cd config/manager && $(KUSTOMIZE) edit set image controller=${IMG}
126124
$(KUSTOMIZE) build config/default | kubectl apply -f -
127125

128-
openshift-deploy: manifests kustomize ## Deploy controller to the K8s cluster specified in ~/.kube/config.
129-
VAL="${RH_RBAC_IMAGE}" yq e '.spec.template.spec.containers[0].image = strenv(VAL)' -i config/default/manager_auth_proxy_patch.yaml
130-
cd config/manager && $(KUSTOMIZE) edit set image controller=${IMG}
131-
$(KUSTOMIZE) build config/default | kubectl apply -f -
132-
133126
undeploy: ## Undeploy controller from the K8s cluster specified in ~/.kube/config.
134127
$(KUSTOMIZE) build config/default | kubectl delete -f -
135128

openshift.Dockerfile

-37
This file was deleted.

0 commit comments

Comments
 (0)