-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add baseline project files, Dockerfile and CI/CD pipeline to deploy it
on commit
- Loading branch information
1 parent
2547c88
commit 58857b0
Showing
6 changed files
with
128 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
name: CI/CD | ||
on: | ||
push: | ||
paths-ignore: | ||
- .gitignore | ||
- LICENSE | ||
- README.md | ||
|
||
env: | ||
PLATFORMS: linux/amd64,linux/arm64,linux/386,linux/arm/v7 | ||
|
||
jobs: | ||
build: | ||
name: Build multi-arch Docker image and cache it | ||
runs-on: ubuntu-latest | ||
outputs: | ||
tags: ${{ steps.tags.outputs.tags }} | ||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v3 | ||
- name: Retrieve Docker build cache | ||
uses: actions/cache@v3 | ||
id: cache | ||
with: | ||
path: /tmp/.buildx-cache | ||
key: buildx-cache-${{ hashFiles('Dockerfile') }} | ||
restore-keys: buildx-cache- | ||
- name: Generate image tags | ||
id: tags | ||
uses: docker/metadata-action@v3 | ||
with: | ||
images: ghcr.io/noah-friedman/amadeus | ||
flavor: latest=true | ||
tags: type=sha | ||
- name: Create Docker Buildx builder | ||
if: steps.cache.outputs.cache-hit != 'true' | ||
run: docker buildx create --use --driver=docker-container | ||
- name: Build and cache multi-platform image | ||
if: steps.cache.outputs.cache-hit != 'true' | ||
uses: docker/build-push-action@v4 | ||
with: | ||
context: . | ||
tags: ${{ steps.tags.outputs.tags }} | ||
platforms: ${{ env.PLATFORMS }} | ||
cache-from: type=local,src=/tmp/.buildx-cache | ||
cache-to: type=local,dest=/tmp/.buildx-cache,mode=max,compression=gzip,compression-level=9 | ||
|
||
verify: | ||
name: Verify project builds in Docker image environment | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v3 | ||
- name: Retrieve Docker build cache | ||
uses: actions/cache/restore@v3 | ||
with: | ||
path: /tmp/.buildx-cache | ||
key: buildx-cache-${{ hashFiles('Dockerfile') }} | ||
restore-keys: buildx-cache- | ||
- name: Build Docker image from cache | ||
uses: docker/build-push-action@v4 | ||
with: | ||
context: . | ||
load: true | ||
cache-from: type=local,src=/tmp/.buildx-cache | ||
tags: ghcr.io/noah-friedman/amadeus | ||
- name: Verify that the project builds successfully | ||
run: docker run --rm ghcr.io/noah-friedman/amadeus | ||
|
||
push: | ||
name: Push Docker image from cache to GitHub Container Registry | ||
runs-on: ubuntu-latest | ||
needs: [build, verify] | ||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v3 | ||
- name: Retrieve Docker build cache | ||
uses: actions/cache/restore@v3 | ||
with: | ||
path: /tmp/.buildx-cache | ||
key: buildx-cache-${{ hashFiles('Dockerfile') }} | ||
restore-keys: buildx-cache- | ||
- name: Create Docker Buildx builder | ||
run: docker buildx create --use --driver=docker-container | ||
- name: Login to GitHub Container Registry | ||
uses: docker/login-action@v2 | ||
with: | ||
registry: ghcr.io | ||
username: ${{ github.actor }} | ||
password: ${{ secrets.GITHUB_TOKEN }} | ||
- name: Build and push multi-platform image | ||
uses: docker/build-push-action@v4 | ||
with: | ||
context: . | ||
push: true | ||
tags: ${{ needs.build.outputs.tags }} | ||
platforms: ${{ env.PLATFORMS }} | ||
cache-from: type=local,src=/tmp/.buildx-cache |
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,3 +1,4 @@ | ||
build | ||
.cache | ||
.DS_Store | ||
.actrc |
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,7 @@ | ||
cmake_minimum_required(VERSION 3.24) | ||
|
||
project(A.M.a.D.E.U.S) | ||
|
||
set(CMAKE_C_STANDARD 17) | ||
|
||
add_executable(amadeus main.c) |
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,12 @@ | ||
# Use alpine to simplify the installation of cmake and make | ||
FROM alpine:latest | ||
RUN apk add --no-cache cmake make gcc g++ | ||
|
||
# Create a directory for the project | ||
RUN mkdir /amadeus | ||
WORKDIR /amadeus | ||
COPY CMakeLists.txt . | ||
COPY main.c . | ||
|
||
# By default, build the project | ||
CMD ["/bin/sh", "-c", "cmake -S . -B build && cmake --build build"] |
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,15 +1,20 @@ | ||
# The A.M.a.D.E.U.S. (<u>A</u>ppropriately <u>M</u>enial <u>a</u>nd <u>D</u>eployable <u>E</u>asily <u>U</u>nderstandable <u>S</u>ample) Project | ||
# The A.M.a.D.E.U.S. (*A*ppropriately *M*enial *a*nd *D*eployable *E*asily *U*nderstandable *S*ample) Project | ||
|
||
Often times I find myself in need of a simple example project to use to test some other external system. | ||
I'm bored of re-writing that project, so I'm just going to put it in a GH repo now. | ||
|
||
|
||
This project uses CMake in order to provide a two-step build process for slightly more complexity (and thus, testable behaviour). | ||
The actual program is a simple number guessing game. | ||
The actual program is a simple number guessing game. A docker image is built on each commit (after first testing that the project | ||
will build), and is built as a multi-platform image to avoid any errors on `arm64` systems. This makes the integration of the | ||
A.M.a.D.E.U.S. Project into any pipeline/CI-CD environment simple. | ||
|
||
The A.M.a.D.E.U.S. Project is programmed using the C language to avoid having to install many external build dependencies | ||
(almost all modern systems provide a C compiler out of the box, and CMake installation is trivial). No code libraries | ||
are required to build this project. Please [open a ticket on GitHub](https://github.com/noah-friedman/amadeus/issues/new/choose) | ||
if you find any bugs. | ||
|
||
Feel free to use as needed. | ||
<br /> | ||
|
||
<br /><br /><br /> | ||
--- | ||
© Noah Friedman 2023 |
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 @@ | ||
int main() {} |