Skip to content

Commit 9127891

Browse files
Add Initial Docker Images (#2)
* Remove sample files that are not needed * Add new Docker Images to build * Add new workflow to build Docker Images * Push a new README * Add final state for a required check * Sure up workflow
1 parent 1a0b217 commit 9127891

File tree

14 files changed

+228
-112
lines changed

14 files changed

+228
-112
lines changed

Diff for: .github/workflows/docker_publish.yml

+128
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
name: Build & Publish Docker Images
2+
3+
on:
4+
push:
5+
branches: [ 'main' ]
6+
pull_request:
7+
env:
8+
REGISTRY: ghcr.io
9+
NAMESPACED_REGISTRY: ghcr.io/apollographql/ci-utility-docker-images
10+
11+
jobs:
12+
calculate-images-to-build:
13+
name: Calculate Images To Build
14+
runs-on: ubuntu-latest
15+
outputs:
16+
changed_dirs: ${{ steps.filter_config_directories.outputs.changed_dirs }}
17+
steps:
18+
- name: "Checkout repository"
19+
uses: actions/checkout@v4
20+
- name: "Calculate changed files directories"
21+
id: calculate_changed_files
22+
uses: tj-actions/changed-files@v44
23+
with:
24+
dir_names: true
25+
dir_names_exclude_current_dir: true
26+
json: true
27+
- name: "Filter out config directories"
28+
id: filter_config_directories
29+
run: |
30+
CHANGED_DIRS=$(echo "${{ steps.calculate_changed_files.outputs.all_changed_files }}" | jq -c '[.[] | select(. | contains(".") | not)'])
31+
echo "changed_dirs=$CHANGED_DIRS" >> "$GITHUB_OUTPUT"
32+
build-and-push-images:
33+
runs-on: ubuntu-latest
34+
permissions:
35+
contents: read
36+
packages: write
37+
attestations: write
38+
id-token: write
39+
needs:
40+
- calculate-images-to-build
41+
strategy:
42+
matrix:
43+
changed_dir: ${{ fromJSON(needs.calculate-images-to-build.outputs.changed_dirs ) }}
44+
steps:
45+
- name: Checkout repository
46+
uses: actions/checkout@v4
47+
- name: Log in to the Container Registry
48+
uses: docker/login-action@65b78e6e13532edd9afa3aa52ac7964289d1a9c1
49+
with:
50+
registry: ${{ env.REGISTRY }}
51+
username: ${{ github.actor }}
52+
password: ${{ secrets.GITHUB_TOKEN }}
53+
- name: Extract Details From config.yml
54+
id: extract_from_config_yaml
55+
run: |
56+
echo "desired_version=$(cat ${{ github.workspace }}/${{ matrix.changed_dir }}/config.yml | yq '.version')" >> "$GITHUB_OUTPUT"
57+
echo "platforms=$(cat ${{ github.workspace }}/${{ matrix.changed_dir }}/config.yml | yq '.platforms | join(",")')" >> "$GITHUB_OUTPUT"
58+
echo "description=$(cat ${{ github.workspace }}/${{ matrix.changed_dir }}/config.yml | yq '.description')" >> "$GITHUB_OUTPUT"
59+
- name: Check Image to Build Does Not Already Exist
60+
run: |
61+
if docker manifest inspect ${{ env.NAMESPACED_REGISTRY }}/${{ matrix.changed_dir }}:${{ steps.extract_from_config_yaml.outputs.desired_version }} > /dev/null; then
62+
echo "The tag "${{ env.NAMESPACED_REGISTRY }}/${{ matrix.changed_dir }}:${{ steps.extract_from_config_yaml.outputs.desired_version }}" already exists in the repository. Do you need to bump the version in the config.yml?"
63+
exit 1
64+
fi
65+
- name: Calculate Version
66+
id: calculate_version
67+
run: |
68+
VERSION=${{ github.event_name == 'pull_request' && format('{0}-PR{1}.{2}', steps.extract_from_config_yaml.outputs.desired_version, github.event.number, github.event.pull_request.head.sha) || steps.extract_from_config_yaml.outputs.desired_version}}
69+
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
70+
- name: Set up Docker Buildx
71+
uses: docker/setup-buildx-action@v3
72+
- name: Get Docker Metadata
73+
id: meta
74+
uses: docker/metadata-action@v5
75+
env:
76+
DOCKER_METADATA_PR_HEAD_SHA: true
77+
with:
78+
images: ${{ env.NAMESPACED_REGISTRY }}/${{ matrix.changed_dir }}
79+
tags: |
80+
type=semver,pattern={{version}},value=v${{ steps.calculate_version.outputs.version }}
81+
type=sha,prefix=
82+
labels: |
83+
org.opencontainers.image.title=${{ matrix.changed_dir }}
84+
org.opencontainers.image.description=${{ steps.extract_from_config_yaml.outputs.description }}
85+
org.opencontainers.image.vendor=Apollo GraphQL
86+
org.opencontainers.image.licenses=MIT
87+
annotations: |
88+
org.opencontainers.image.title=${{ matrix.changed_dir }}
89+
org.opencontainers.image.description=${{ steps.extract_from_config_yaml.outputs.description }}
90+
org.opencontainers.image.vendor=Apollo GraphQL
91+
org.opencontainers.image.licenses=MIT
92+
- name: Build and Push Docker image
93+
id: push
94+
uses: docker/build-push-action@v6
95+
with:
96+
context: ${{ github.workspace }}/${{ matrix.changed_dir }}
97+
file: ${{ github.workspace }}/${{ matrix.changed_dir }}/Dockerfile
98+
push: true
99+
tags: ${{ steps.meta.outputs.tags }}
100+
annotations: ${{ steps.meta.outputs.annotations }}
101+
labels: ${{ steps.meta.outputs.labels }}
102+
platforms: ${{ steps.extract_from_config_yaml.outputs.platforms }}
103+
- name: Create Git Tag
104+
uses: mathieudutour/github-tag-action@v6.2
105+
with:
106+
github_token: ${{ secrets.GITHUB_TOKEN }}
107+
default_bump: false
108+
default_prerelease_bump: false
109+
custom_tag: ${{ matrix.changed_dir }}/v${{ steps.calculate_version.outputs.version }}
110+
dry_run: ${{ github.event_name == 'pull_request' }}
111+
tag_prefix: ""
112+
- name: Create GitHub Release
113+
if: ${{ github.event_name != 'pull_request' }}
114+
uses: comnoco/create-release-action@v2.0.5
115+
with:
116+
tag_name: ${{ matrix.changed_dir }}/v${{ steps.calculate_version.outputs.version }}
117+
release_name: ${{ matrix.changed_dir }} - v${{ steps.calculate_version.outputs.version }}
118+
check-builds-all-completes:
119+
name: Docker Images Built & Pushed
120+
if: ${{ always() }}
121+
runs-on: ubuntu-latest
122+
needs:
123+
- build-and-push-images
124+
steps:
125+
- run: |
126+
exit ${{ (contains(needs.*.result, 'failure') || contains(needs.*.result, 'cancelled') || contains(needs.*.result, 'skipped')) && 1 || 0 }}
127+
128+

Diff for: .gitignore

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
node_modules
2-
package-lock.json
31
.DS_Store
42
.dist
53
*.swp
4+
.idea/**

Diff for: CODEOWNERS

+1-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1 @@
1-
# This file was automatically generated by the Apollo SecOps team
2-
# Please customize this file as needed prior to merging.
3-
4-
* @abernix
1+
* @apollographql/betelgeuse

Diff for: README.md

+7-30
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,9 @@
1-
# Spec Template
1+
# CI Utility Docker Images
22

3-
## Getting Started
3+
This repo allows building of images that are used in other apollographl repos for **CI only**
44

5-
1. Click the "Use this template" button on this repository to create a copy of it and name the new repository `specs-{{spec_name}}`, per convention.
6-
1. Search for usages of `%%SPEC-.*?%%` tokens within this repository and replace them with appropriate names (e.g., `%%SPEC-NAME%%`, `%%SPEC-TITLE%%` and `%%SPEC-VERSION%%`).
7-
1. Setup the new repository with Netlify (estimated about 5 minutes)
8-
1. Go to [Netlify App](https://app.netlify.com/teams/apollo/sites)
9-
1. Click “New Site From Git” button
10-
1. Choose GitHub
11-
1. Authorize
12-
1. Choose `apollographql` org
13-
1. Search for `specs-{{spec_name}}`
14-
1. It probably won’t come up
15-
1. Choose “Configure Netlify on GitHub”
16-
1. On the “Install Netlify” screen choose `apollographql`
17-
1. Scroll to the bottom of the App page to where you see the option for “Only select repositories” inside “Repository access”
18-
1. Click “Select repositories”
19-
1. Type `specs-{{spec_name}}` again, then click the matching name.
20-
1. Click on “Save”
21-
1. Then, back on Netlify, click on “specs-tag” in the “Continuous Deployment: GitHub App” box.
22-
1. Leave all the defaults as they are and press “Deploy site”
23-
1. Click on “Site Settings”
24-
1. Press “Change Site Name”
25-
1. Type `apollo-specs-{{spec_name}}` as the name and press “Save”
26-
1. The site should now work at `https://apollo-specs-{{spec_name}}.netlify.app/`
27-
1. Click on “Build and Deploy” on the left menu
28-
1. Under “Branches” press “Edit Settings”
29-
1. Change the “Branch deploys” option to “All” and press “Save”
30-
1. Setup proxying redirects to the new sub-spec site [on the `specs` repo](https://github.com/apollographql/specs/blob/main/_redirects). This will make it available at `https://specs.apollo.dev/{{spec_name}}`.
31-
1. Run `npm run dev` to watch and rebuild. Just use a browser to view `.dist/index.html` to see the rendered page.
32-
1. Write the actual specifications. _Use other specifications (like [the `core` specification](https://github.com/apollographql/specs-core)) as your guide._
5+
## Adding a new image
6+
7+
To add a new image, the easiest method is to copy an existing folder at the top level of the repo.
8+
Then you can change its name and update the Dockerfile to allow it to build your new image. The automated
9+
CI checks should take care of everything else.

Diff for: binary-builder-glibc/Dockerfile

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# The SHA below is rockylinux:8.9.20231119, fixing to a specific SHA
2+
# rather than a mutable tag, stops rebuilds completely changing the
3+
# contents of the container without us realising.
4+
FROM rockylinux@sha256:9794037624aaa6212aeada1d28861ef5e0a935adaf93e4ef79837119f2a2d04c
5+
6+
ARG RUST_VERSION=1.80.1
7+
ARG NODE_VERSION=20.15.1
8+
9+
# Add .cargo/bin to PATH
10+
ENV VOLTA_HOME=/root/.volta
11+
ENV PATH="$VOLTA_HOME/bin:/root/.cargo/bin:${PATH}"
12+
13+
# First update all the installed packages
14+
RUN yum -y update
15+
16+
# Add the Development Tools
17+
RUN yum groupinstall -y "Development Tools"
18+
19+
# Add some extra utilities for building in Rust
20+
RUN yum install -y perl-core openssl-devel cmake
21+
22+
# Install RustUp and add specific target
23+
RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | bash -s -- -y --default-toolchain=$RUST_VERSION
24+
25+
RUN case $TARGETPLATFORM in \
26+
linux/amd64) \
27+
rustup add target x86_64-unknown-linux-gnu \
28+
;; \
29+
linux/arm64) \
30+
rustup add target aarch64-unknown-linux-gnu \
31+
;; \
32+
*) \
33+
echo "TARGETPLATFORM $TARGETPLATFORM not recognised, not installing a target" \
34+
;; \
35+
esac
36+
37+
# Install Volta (and Node)
38+
RUN curl https://get.volta.sh | bash
39+
RUN volta install node@$NODE_VERSION

Diff for: binary-builder-glibc/README.md

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Binary Builder (`glibc`)
2+
3+
The image contained herein is an image that should be used
4+
to _build_ Rust binaries at Apollo.
5+
6+
It contains RockyLinux (https://rockylinux.org/) at version
7+
8.9, which specifically contains `glibc` 2.28.
8+
9+
Using images like this ensures compatability with the broadest
10+
range of Linux distributions that are currently under an LTS policy,
11+
and ensures compliance with our new standards for Rust binary building.

Diff for: binary-builder-glibc/config.yml

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
version: 0.1.0
2+
description: Builder image for Rust binaries that must be built with glibc 2.28
3+
platforms:
4+
- linux/arm64
5+
- linux/amd64

Diff for: binary-builder-musl/Dockerfile

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# The SHA below is rust:1.80.1-alpine3.19, fixing to a specific SHA
2+
# rather than a mutable tag, stops rebuilds completely changing the
3+
# contents of the container without us realising.
4+
FROM rust@sha256:b3ac1f65cf33390407c9b90558eb41e7a8311c47d836fca5800960f1aa2d11d5
5+
6+
# Update packages and package manager to keep us current
7+
RUN apk update && apk upgrade
8+
9+
# Add tools to enable `musl` compilation and other utilities when building in Rust
10+
RUN apk add musl-dev curl cmake openssl gcc nodejs
11+
12+
# Add the specific `musl` target to make sure we don't build for `glibc` by accident
13+
RUN case $TARGETPLATFORM in \
14+
linux/amd64) \
15+
rustup add target x86_64-unknown-linux-musl \
16+
;; \
17+
linux/arm64) \
18+
rustup add target aarch64-unknown-linux-musl \
19+
;; \
20+
*) \
21+
echo "TARGETPLATFORM $TARGETPLATFORM not recognised, not installing a target" \
22+
;; \
23+
esac

Diff for: binary-builder-musl/README.md

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Binary Builder (`musl`)
2+
3+
The image contained herein is an image that should be used
4+
to _build_ Rust binaries at Apollo.
5+
6+
It contains Alpine 3.19, and Rust at version 1.80.1 and is based on the published rust images.
7+
8+
Using images like this ensures compliance with our new standards for Rust binary building.

Diff for: binary-builder-musl/config.yml

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
version: 0.1.0
2+
description: Builder image for Rust binaries that must be built with musl
3+
platforms:
4+
- linux/arm64
5+
- linux/amd64

Diff for: netlify.toml

-6
This file was deleted.

Diff for: package.json

-19
This file was deleted.

Diff for: spec.graphql

-1
This file was deleted.

Diff for: spec.md

-50
This file was deleted.

0 commit comments

Comments
 (0)