Skip to content

Commit

Permalink
first test at passing image
Browse files Browse the repository at this point in the history
  • Loading branch information
Emterry committed Mar 5, 2024
1 parent 31a7465 commit 586cf28
Show file tree
Hide file tree
Showing 10 changed files with 266 additions and 6 deletions.
18 changes: 18 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
root = true

[*]
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true

[*.json]
indent_style = space
indent_size = 2

[*.sh]
indent_style = space
indent_size = 2

[{*.yml,*.yaml}]
indent_style = space
indent_size = 2
3 changes: 0 additions & 3 deletions .github/CODEOWNERS

This file was deleted.

26 changes: 26 additions & 0 deletions .github/workflows/build-and-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
---
name: Build and Test

on:
pull_request:
branches:
- main

permissions: {}

jobs:
build-and-test:
name: Build and Test
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- name: Checkout
id: checkout
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1

- name: Build and Test
id: build_and_test
shell: bash
run: |
bash scripts/build-and-test.sh
55 changes: 55 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
---
name: Release

on:
push:
tags:
- "*"

permissions: {}

jobs:
release:
name: Release
runs-on: ubuntu-latest
permissions:
contents: read
id-token: write
packages: write
steps:
- name: Checkout
id: checkout
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1

- name: Install cosign
id: install_cosign
uses: sigstore/cosign-installer@e1523de7571e31dbe865fd2e80c5c7c23ae71eb4 # v3.4.0

- name: Log in to GitHub Container Registry
id: login_ghcr
uses: docker/login-action@343f7c4344506bcbf9b4de18042ae17996df046d # v3.0.0
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build and Push
id: build_and_push
uses: docker/build-push-action@4a13e500e55cf31b7a5d59a38ab2040ab0f42f56 # v5.1.0
with:
push: true
tags: ghcr.io/${{ github.repository }}:${{ github.ref_name }}

- name: Sign
id: sign
shell: bash
run: |
cosign sign --yes ghcr.io/${{ github.repository }}@${{ steps.build_and_push.outputs.digest }}
- name: Verify
id: verify
run: |
cosign verify \
--certificate-oidc-issuer=https://token.actions.githubusercontent.com \
--certificate-identity=https://github.com/${{ github.repository }}/.github/workflows/release.yml@refs/tags/${{ github.ref_name }} \
ghcr.io/${{ github.repository }}@${{ steps.build_and_push.outputs.digest }}
34 changes: 34 additions & 0 deletions .github/workflows/super-linter.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
---
name: Super-Linter

on:
pull_request:
branches:
- main
types:
- edited
- opened
- reopened
- synchronize

permissions: {}

jobs:
super-linter:
name: Super-Linter
runs-on: ubuntu-latest
permissions:
contents: read
statuses: write
steps:
- name: Checkout
id: checkout
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
with:
fetch-depth: 0

- name: Run Super-Linter
id: super_linter
uses: super-linter/super-linter/slim@25003d0370b45d97187597838ecb9fdadfc08aea # v6.2.0
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
1 change: 1 addition & 0 deletions CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* @ministryofjustice/analytical-platform
53 changes: 53 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
FROM public.ecr.aws/ubuntu/ubuntu@sha256:722b3bddfe96b95441f626cf94974d79213090ecbd16954f71d7c080fb413561

LABEL org.opencontainers.image.vendor="Ministry of Justice" \
org.opencontainers.image.authors="Analytical Platform ([email protected])"
# uncomment if required to your repository details
#org.opencontainers.image.title="{image title}" \
#org.opencontainers.image.description="{decription}" \
#org.opencontainers.image.url="https://github.com/ministryofjustice/analytical-platform"

ENV CONTAINER_USER="analyticalplatform" \
CONTAINER_UID="1000" \
CONTAINER_GROUP="analyticalplatform" \
CONTAINER_GID="1000" \
DEBIAN_FRONTEND="noninteractive"

# User
RUN groupadd \
--gid ${CONTAINER_GID} \
${CONTAINER_GROUP} \
&& useradd \
--uid ${CONTAINER_UID} \
--gid ${CONTAINER_GROUP} \
--create-home \
--shell /bin/bash \
${CONTAINER_USER}

# Base
RUN apt-get update --yes \
&& apt-get install --yes \
"apt-transport-https=2.4.11" \
"curl=7.81.0-1ubuntu1.15" \
"git=1:2.34.1-1ubuntu1.10" \
"gpg=2.2.27-3ubuntu2.1" \
"python3.10=3.10.12-1~22.04.3" \
"python3-pip=22.0.2+dfsg-1ubuntu0.4" \
"unzip=6.0-26ubuntu3.2" \
&& apt-get clean --yes \
&& rm --force --recursive /var/lib/apt/lists/*

USER ${CONTAINER_USER}

WORKDIR /home/${CONTAINER_USER}

# Basic health check that always returns a success status
HEALTHCHECK CMD true

# Place build logic here:
# Example
# COPY . /home/${CONTAINER_USER}
# RUN python -m pip install --no-cache-dir --upgrade pip==23.3.1 \
# && python -m pip install --no-cache-dir --requirement requirements.txt

# CMD ["foo.handler"]
33 changes: 30 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,20 +1,37 @@
# Ministry of Justice Template Repository
# Analytical Platform Image Build Template

[![repo standards badge](https://img.shields.io/endpoint?labelColor=231f20&color=005ea5&style=for-the-badge&label=MoJ%20Compliant&url=https%3A%2F%2Foperations-engineering-reports.cloud-platform.service.justice.gov.uk%2Fapi%2Fv1%2Fcompliant_public_repositories%2Fendpoint%2Ftemplate-repository&logo=data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACgAAAAoCAYAAACM/rhtAAAABmJLR0QA/wD/AP+gvaeTAAAHJElEQVRYhe2YeYyW1RWHnzuMCzCIglBQlhSV2gICKlHiUhVBEAsxGqmVxCUUIV1i61YxadEoal1SWttUaKJNWrQUsRRc6tLGNlCXWGyoUkCJ4uCCSCOiwlTm6R/nfPjyMeDY8lfjSSZz3/fee87vnnPu75z3g8/kM2mfqMPVH6mf35t6G/ZgcJ/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JUp7ehY5a6Tl2jjmVvitF9fxo5Yq8CaAfAkzLMnySt6uz/1k6bPx59CpCNxGfoSKA30IPoH7cQXdArwCOllFX/i53P5P9a/gNkKpsCMFRuFAAAAABJRU5ErkJggg==)](https://operations-engineering-reports.cloud-platform.service.justice.gov.uk/public-report/template-repository)

This template repository equips you with the default initial files required for a Ministry of Justice GitHub repository.
This template repository equips you with the default initial files required for an Analytical Platform Image Build Template GitHub repository.

This repository is managed in Terraform [here](https://github.com/ministryofjustice/data-platform/blob/main/terraform/github/analytical-platform-repositories.tf#L286).

## Included Files

The repository comes with the following preset files:

- .GitHub
- workflows
- built-and-test.yml
- release.yml
- super-linter.yml
- dependency-review.yml
- scripts
- build-and-test.sh
- test
- container-structure-test.yml
- Dockerfile
- .EditorConfig
- LICENSE
- .gitignore
- CODEOWNERS
- dependabot.yml
- GitHub Actions example files
- Ministry of Justice Compliance Badge (public repositories only)

## Features

The base container image is [Ubuntu 22.04 LTS](https://gallery.ecr.aws/ubuntu/ubuntu).

## Setup Instructions

Once you've created your repository using this template, ensure the following steps:
Expand Down Expand Up @@ -64,3 +81,13 @@ Adapt the dependabot.yml file to match your project's [dependency manager](https
### Dependency Review

If your repository is private with no GitHub Advanced Security license, remove the `.github/workflows/dependency-review.yml` file.

### Dockerfile

make sure to add your own build logic to the bottom of the `Dockerfile`

### Tests

please make sure to add any additional requirement tests needed to the `container-structure-test.yml`

please note: No testing as been added to this template this is to be implemented by the developer as required
24 changes: 24 additions & 0 deletions scripts/build-and-test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/usr/bin/env bash

IMAGE_TAG="analytical-platform.service.justice.gov.uk/template-base:local"
CONTAINER_STRUCTURE_TEST_IMAGE="gcr.io/gcp-runtimes/container-structure-test:latest"

if [[ "${REMOTE_CONTAINERS}" ]] && [[ "$(uname -m)" == "aarch64" ]]; then
echo "(⚠) Looks like you're running in a dev container on Apple Silicon."
echo "(⚠) This script builds linux/amd64 images which might take a long time or even fail."
export PLATFORM_FLAG="--platform linux/amd64"
fi
# shellcheck disable=SC2086
# special case for PLATFORM_FLAG as it can't parse double quotes
docker build ${PLATFORM_FLAG} --file Dockerfile --tag "${IMAGE_TAG}" .

echo "Running container structure test for [ ${IMAGE_TAG} ]"

# shellcheck disable=SC2086
# special case for PLATFORM_FLAG as it can't parse double quotes
docker run --rm ${PLATFORM_FLAG} \
--volume /var/run/docker.sock:/var/run/docker.sock \
--volume "${PWD}:/workspace" \
--workdir /workspace \
"${CONTAINER_STRUCTURE_TEST_IMAGE}" \
test --image "${IMAGE_TAG}" --config "/workspace/test/container-structure-test.yml"
25 changes: 25 additions & 0 deletions test/container-structure-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
---
schemaVersion: 2.0.0

containerRunOptions:
user: "analyticalplatform"

commandTests:
- name: "ubuntu"
command: "grep"
args: ["DISTRIB_RELEASE", "/etc/lsb-release"]
expectedOutput: ["DISTRIB_RELEASE=22.04"]

- name: "whoami"
command: "whoami"
expectedOutput: ["analyticalplatform"]

- name: "user"
command: "id"
args: ["--user", "analyticalplatform"]
expectedOutput: ["1000"]

- name: "groups"
command: "id"
args: ["--groups", "analyticalplatform"]
expectedOutput: ["100"]

0 comments on commit 586cf28

Please sign in to comment.