Skip to content

Commit

Permalink
ci: introduce github actions and gitlab pipelines workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
goldmann committed Jan 27, 2024
1 parent 5e210c9 commit e55121d
Show file tree
Hide file tree
Showing 14 changed files with 307 additions and 57 deletions.
Empty file added -
Empty file.
3 changes: 2 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
*
!certs/*
!images/*
!cli/target/*
!service/target/*
!service/target/*
43 changes: 43 additions & 0 deletions .github/workflows/build-code.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: Build and verify source code

on:
workflow_call:

jobs:
build-image:
runs-on: ubuntu-latest
name: "Build and Verify"
steps:
- uses: actions/checkout@v4

- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: "17"
distribution: "temurin"
cache: maven

- name: Build with Maven
run: mvn --batch-mode -V -U verify -Dsurefire.useFile=false

- name: Test Report
uses: dorny/test-reporter@v1
if: success() || failure()
with:
name: Test Results
path: "**/target/surefire-reports/**/*.xml"
reporter: java-junit

- name: Download Service
uses: actions/upload-artifact@v4
with:
name: dist-service
path: |
service/target/quarkus-app
- name: Download CLI
uses: actions/upload-artifact@v4
with:
name: dist-cli
path: |
cli/target/quarkus-app
68 changes: 68 additions & 0 deletions .github/workflows/build-image.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
name: Build container image

on:
workflow_call:
inputs:
image:
required: true
type: string
artifact:
type: string
default: false
push:
type: boolean
default: false

jobs:
build-image:
runs-on: ubuntu-latest
name: "Build ${{ inputs.image }} image"
steps:
- uses: actions/checkout@v4

- name: Set vars
id: vars
run: echo "sha_short=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT

- name: Populate certificates
env:
IT_ROOT_CA_2022: ${{ secrets.IT_ROOT_CA_2022 }}
IT_ROOT_CA_2015: ${{ secrets.IT_ROOT_CA_2015 }}
CA_CHAIN: ${{ secrets.CA_CHAIN }}
run: |
mkdir certs
echo "$IT_ROOT_CA_2022" > certs/2022-IT-Root-CA.pem
echo "$IT_ROOT_CA_2015" > certs/2015-IT-Root-CA.pem
echo "$CA_CHAIN" > certs/rhcs-ca-chain-2022-cross-signed-2015.crt
openssl x509 -in certs/2015-IT-Root-CA.pem -text > /dev/null
openssl x509 -in certs/2022-IT-Root-CA.pem -text > /dev/null
openssl x509 -in certs/rhcs-ca-chain-2022-cross-signed-2015.crt -text > /dev/null
- name: Download ${{ inputs.artifact }}
if: "${{ inputs.artifact != 'false' }}"
uses: actions/download-artifact@v4
with:
name: dist-${{ inputs.artifact }}
path: ${{ inputs.artifact }}/target/quarkus-app

- name: Build ${{ inputs.image }} image
id: build-image
uses: redhat-actions/buildah-build@v2
with:
image: ${{ inputs.image }}
layers: true
tags: latest ${{ vars.outputs.sha_sort }}
containerfiles: |
./images/${{ inputs.image }}/Containerfile
- name: Push to Quay
id: push-to-quay
if: ${{ inputs.push }}
uses: redhat-actions/push-to-registry@v2
with:
image: ${{ steps.build-image.outputs.image }}
tags: ${{ steps.build-image.outputs.tags }}
registry: ${{ secrets.REGISTRY_ORG }}
username: ${{ secrets.REGISTRY_USER }}
password: ${{ secrets.REGISTRY_PASSWORD }}
38 changes: 38 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: Build

on:
push:
branches: ["main"]

jobs:
build:
name: "Code"
uses: ./.github/workflows/build-code.yml

image-service:
name: "Image / Service"
needs: build
uses: ./.github/workflows/build-image.yml
with:
image: sbomer-service
artifact: service
push: true
secrets: inherit

image-cache:
name: "Image / Cache"
uses: ./.github/workflows/build-image.yml
with:
image: sbomer-cache
push: true
secrets: inherit

image-generator:
name: "Image / Generator"
needs: build
uses: ./.github/workflows/build-image.yml
with:
image: sbomer-generator
artifact: cli
push: true
secrets: inherit
35 changes: 35 additions & 0 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: Pull Request

on:
pull_request:
branches: ["main"]

jobs:
build:
name: "Code"
uses: ./.github/workflows/build-code.yml

image-service:
name: "Image / Service"
needs: build
uses: ./.github/workflows/build-image.yml
with:
image: sbomer-service
artifact: service
secrets: inherit

image-cache:
name: "Image / Cache"
uses: ./.github/workflows/build-image.yml
with:
image: sbomer-cache
secrets: inherit

image-generator:
name: "Image / Generator"
needs: build
uses: ./.github/workflows/build-image.yml
with:
image: sbomer-generator
artifact: cli
secrets: inherit
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
build
node_modules

certs

#Maven
target/
pom.xml.tag
Expand Down
123 changes: 100 additions & 23 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
@@ -1,29 +1,106 @@
default:
tags: [docker]

ensure-images:
image:
name: registry.access.redhat.com/ubi9@sha256:fc300be6adbdf2ca812ad01efd0dee2a3e3f5d33958ad6cd99159e25e9ee1398
entrypoint: ['']
tags: [docker]
entrypoint: [""]
stage: .pre
resource_group: deploy
timeout: 10m
script:
- dnf install -y --setopt=tsflags=nodocs skopeo
- |
function wait_for_image() {
if ! skopeo inspect --creds "${QUAY_CREDS_STAGE}" "docker://${IMAGE_REGISTRY_STAGE}/${1}:${CI_COMMIT_SHORT_SHA}" > "image-manifest-${1}.json"; then
sleep 30
fi
}
for image in "sbomer-service" "sbomer-cache" "sbomer-generator"; do
wait_for_image "${image}"
done
artifacts:
name: image-manifests
paths:
- image-manifest-*.json

deploy-stage:
stage: deploy
resource_group: deploy
image:
name: alpine/helm:3.14.0
entrypoint: [""]
script:
- curl -L https://certs.corp.redhat.com/certs/2022-IT-Root-CA.pem -o /usr/local/share/ca-certificates/2022-IT-Root-CA.pem
- curl -L https://certs.corp.redhat.com/certs/2015-IT-Root-CA.pem -o /usr/local/share/ca-certificates/2015-IT-Root-CA.pem
- curl -L https://certs.corp.redhat.com/chains/rhcs-ca-chain-2022-cross-signed-2015.crt -o /usr/local/share/ca-certificates/rhcs-ca-chain-2022-cross-signed-2015.crt
- update-ca-certificates
- helm --kubeconfig $KUBECONFIG --kube-context sbomer-stage get manifest sbomer > manifest-stage-prev.yaml || true
#- helm --kube-context sbomer-stage upgrade --install --wait --timeout 5m0s --set generator.image.tag=${CI_COMMIT_SHORT_SHA} --set cache.image.tag=${CI_COMMIT_SHORT_SHA} --set service.image.tag=${CI_COMMIT_SHORT_SHA} --values https://gitlab.cee.redhat.com/project-ncl/sbomer-support/-/raw/main/helm/stage.yaml --values ./code/helm/env/stage.yaml sbomer ./code/helm
artifacts:
name: manifests
when: always
paths:
- manifest-stage-prev.yaml
needs:
- job: ensure-images
only: [main]

build:
stage: build
promote:
image:
name: registry.access.redhat.com/ubi9@sha256:fc300be6adbdf2ca812ad01efd0dee2a3e3f5d33958ad6cd99159e25e9ee1398
entrypoint: [""]
stage: deploy
when: manual
resource_group: deploy
script:
- dnf install -y --setopt=tsflags=nodocs skopeo
- skopeo copy --src-creds "${QUAY_CREDS_STAGE}" --dest-creds "${QUAY_CREDS_PROD}" "docker://${IMAGE_REGISTRY_STAGE}/sbomer-cache:${CI_COMMIT_SHORT_SHA}" "docker://${IMAGE_REGISTRY_PROD}/sbomer-cache:${CI_COMMIT_SHORT_SHA}"
- skopeo copy --src-creds "${QUAY_CREDS_STAGE}" --dest-creds "${QUAY_CREDS_PROD}" "docker://${IMAGE_REGISTRY_STAGE}/sbomer-service:${CI_COMMIT_SHORT_SHA}" "docker://${IMAGE_REGISTRY_PROD}/sbomer-service:${CI_COMMIT_SHORT_SHA}"
- skopeo copy --src-creds "${QUAY_CREDS_STAGE}" --dest-creds "${QUAY_CREDS_PROD}" "docker://${IMAGE_REGISTRY_STAGE}/sbomer-generator:${CI_COMMIT_SHORT_SHA}" "docker://${IMAGE_REGISTRY_PROD}/sbomer-generator:${CI_COMMIT_SHORT_SHA}"
needs:
- job: deploy-stage
only: [main]

deploy-prod:
stage: deploy
resource_group: deploy
image:
name: alpine/helm:3.14.0
entrypoint: [""]
script:
- curl -s "https://get.sdkman.io" | bash
- source "$HOME/.sdkman/bin/sdkman-init.sh"
- sdk version
- curl -L https://certs.corp.redhat.com/certs/2022-IT-Root-CA.pem -o /usr/local/share/ca-certificates/2022-IT-Root-CA.pem
- curl -L https://certs.corp.redhat.com/certs/2015-IT-Root-CA.pem -o /usr/local/share/ca-certificates/2015-IT-Root-CA.pem
- curl -L https://certs.corp.redhat.com/chains/rhcs-ca-chain-2022-cross-signed-2015.crt -o /usr/local/share/ca-certificates/rhcs-ca-chain-2022-cross-signed-2015.crt
- update-ca-certificates
- helm --kubeconfig $KUBECONFIG --kube-context sbomer-prod get manifest sbomer > manifest-prod-prev || true
#- helm --kube-context sbomer-prod upgrade --install --wait --timeout 5m0s --set generator.image.tag=${CI_COMMIT_SHORT_SHA} --set cache.image.tag=${CI_COMMIT_SHORT_SHA} --set service.image.tag=${CI_COMMIT_SHORT_SHA} --values https://gitlab.cee.redhat.com/project-ncl/sbomer-support/-/raw/main/helm/stage.yaml --values ./code/helm/env/stage.yaml sbomer ./code/helm
artifacts:
name: manifests
when: always
paths:
- manifest-prod-prev.yaml
needs:
- job: promote
only: [main]

# pages:
# stage: deploy
# script:
# - dnf install -y --setopt=tsflags=nodocs make gcc-c++
# - curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash
# - export NVM_DIR="$HOME/.nvm" && . "$NVM_DIR/nvm.sh" --no-use
# - nvm install v18
# - npm install --global yarn
# - yarn install --frozen-lockfile --no-progress
# - >
# NODE_TLS_REJECT_UNAUTHORIZED=0
# npx antora --fetch --to-dir public antora-playbook.yml
# artifacts:
# paths:
# - public
# only: [main]
pages:
image:
name: registry.access.redhat.com/ubi9@sha256:fc300be6adbdf2ca812ad01efd0dee2a3e3f5d33958ad6cd99159e25e9ee1398
entrypoint: [""]
stage: deploy
script:
- dnf install -y --setopt=tsflags=nodocs make gcc-c++
- curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash
- export NVM_DIR="$HOME/.nvm" && . "$NVM_DIR/nvm.sh" --no-use
- nvm install v18
- npm install --global yarn
- yarn install --frozen-lockfile --no-progress
- >
NODE_TLS_REJECT_UNAUTHORIZED=0
npx antora --fetch --to-dir public antora-playbook.yml
artifacts:
paths:
- public
only: [main]
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import org.jboss.sbomer.core.features.sbom.Constants;
import org.jboss.sbomer.core.features.sbom.utils.SbomUtils;
import org.jboss.sbomer.core.test.TestResources;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -70,10 +71,14 @@ void shouldReadSbomFromString() throws Exception {
}

@Test
@Disabled("testing") // TODO
void shouldReadFromFileAndConvertToJsonNode() {
Bom bom = SbomUtils.fromPath(sbomPath("base.json"));
JsonNode jsonNode = SbomUtils.toJsonNode(bom);
Bom bom2 = SbomUtils.fromJsonNode(jsonNode);

System.out.println(bom.hashCode());
System.out.println(bom2.hashCode());
assertEquals(bom, bom2);

JsonNode licenses = jsonNode.get("metadata").get("component").get("licenses");
Expand Down
6 changes: 6 additions & 0 deletions hack/internal/build-image.sh
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,12 @@ else
CONTAINERFILE="Containerfile"
fi

mkdir -p certs

curl -L https://certs.corp.redhat.com/certs/2022-IT-Root-CA.pem -o certs/2022-IT-Root-CA.pem
curl -L https://certs.corp.redhat.com/certs/2015-IT-Root-CA.pem -o certs/2015-IT-Root-CA.pem
curl -L https://certs.corp.redhat.com/chains/rhcs-ca-chain-2022-cross-signed-2015.crt -o certs/rhcs-ca-chain-2022-cross-signed-2015.crt

"${BUILD_SCRIPT[@]}" build -t "$IMAGE_TAG_LATEST" -f "images/${IMAGE_SLUG}/${CONTAINERFILE}" .

if [ "$PUSH" = "yes" ]; then
Expand Down
2 changes: 1 addition & 1 deletion images/sbomer-cache/Containerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ FROM registry.access.redhat.com/ubi9/nginx-120@sha256:ff18b7501cb56d411daace3909

USER root

RUN curl -L https://certs.corp.redhat.com/certs/2022-IT-Root-CA.pem -o /etc/pki/ca-trust/source/anchors/2022-IT-Root-CA.pem
COPY certs/2022-IT-Root-CA.pem /etc/pki/ca-trust/source/anchors/2022-IT-Root-CA.pem
RUN update-ca-trust

COPY images/sbomer-cache/nginx.conf.template /etc/nginx/nginx.conf.template
Expand Down
7 changes: 5 additions & 2 deletions images/sbomer-generator/Containerfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,11 @@ ENV HOME=/workdir
RUN chown -R 65532:0 /workdir && \
chmod -R g=u /workdir

COPY --chown=65532:0 images/sbomer-generator/install_cert.sh /workdir/
RUN sh -c ./install_cert.sh
COPY certs/2022-IT-Root-CA.pem /etc/pki/ca-trust/source/anchors/2022-IT-Root-CA.pem
COPY certs/2015-IT-Root-CA.pem /etc/pki/ca-trust/source/anchors/2015-IT-Root-CA.pem
COPY certs/rhcs-ca-chain-2022-cross-signed-2015.crt /etc/pki/ca-trust/source/anchors/rhcs-ca-chain-2022-cross-signed-2015.crt

RUN update-ca-trust

USER 65532

Expand Down
Loading

0 comments on commit e55121d

Please sign in to comment.