Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
norio-nomura committed Jul 9, 2024
0 parents commit 48fb005
Show file tree
Hide file tree
Showing 9 changed files with 339 additions and 0 deletions.
36 changes: 36 additions & 0 deletions .github/actions/configure-docker-containerd-image-store/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: 'configure docker containerd image store'
description: 'configure docker containerd image store'
inputs:
USE_CONTAINERD:
description: use containerd as docker image store
required: false
default: 'false'
runs:
using: "composite"
steps:
- run: |
# enable containerd image store
ENABLE_CONTAINERD_IMAGE_STORE=${{ inputs.USE_CONTAINERD }}
[ "$ENABLE_CONTAINERD_IMAGE_STORE" != 'false' ] \
&& ENABLE_CONTAINERD_IMAGE_STORE=true \
|| ENABLE_CONTAINERD_IMAGE_STORE=false
# detect current configuration
config=/etc/docker/daemon.json
current=$((sudo cat "$config" 2>/dev/null || echo "{}")|jq '.features."containerd-snapshotter" // false')
# update configuration if necessary
[ "$current" = "$ENABLE_CONTAINERD_IMAGE_STORE" ] && exit 0
jq_expression='.features."containerd-snapshotter" = '$ENABLE_CONTAINERD_IMAGE_STORE
tmpfile=$(mktemp) && (sudo cat "$config" 2>/dev/null || echo "{}") | jq "$jq_expression" > "$tmpfile"
mkdir -p $(dirname "$config") && (cat "$tmpfile" | sudo tee "$config") && rm "$tmpfile"
# restart docker
sudo systemctl restart docker || sudo journalctl -xeu docker.service
echo ---
docker info
echo ---
docker image ls
echo ---
sudo systemctl status docker
shell: bash
44 changes: 44 additions & 0 deletions .github/actions/install_qemu_user_static_from_debian/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: 'install qemu-user-static from debian'
description: 'install qemu-user-static from debian'
inputs:
VERSION:
description: version of qemu-user-static
required: false
TARGET_RELEASE:
default: bookworm
description: target release specifying to apt-get install
required: false
runs:
using: "composite"
steps:
- id: process
run: |
TARGET_RELEASE=${{ inputs.TARGET_RELEASE }}
VERSION=${{ inputs.VERSION }}
# install debian-archive-keyring
keyring=/etc/apt/keyrings/debian-archive-keyring.gpg
[ -f $keyring ] || curl https://ftp-master.debian.org/keys/archive-key-11.asc -o - | sudo gpg --dearmor -o $keyring
# add debian sources
debian_sources=/etc/apt/sources.list.d/debian-$TARGET_RELEASE.sources
[ -f "$debian_sources" ] || sudo tee $debian_sources <<EOF
Types: deb
URIs: http://deb.debian.org/debian
Suites: $TARGET_RELEASE
Components: main
Signed-By: $keyring
EOF
# pin debian sources
debian_pin=/etc/apt/preferences.d/debian-$TARGET_RELEASE-pin
[ -f "$debian_pin" ] || sudo tee $debian_pin <<EOF
Package: *
Pin: release n=$TARGET_RELEASE
Pin-Priority: 100
EOF
TARGET_FLAG=${TARGET_RELEASE:+-t $TARGET_RELEASE}
VERSION_REQUIREMENT=${VERSION:+=$VERSION}
sudo apt-get update && sudo apt-get $TARGET_FLAG install -y qemu-user-static$VERSION_REQUIREMENT
shell: bash
154 changes: 154 additions & 0 deletions .github/workflows/docker-image-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
name: Docker Image CI

on:
create:
push:
branches: [master]
paths:
- '.github/actions/*/action.yml'
- '.github/workflows/docker-image-ci.yml'
- 'Dockerfile'
- '**.swift'
pull_request:
paths:
- '.github/actions/*/action.yml'
- '.github/workflows/docker-image-ci.yml'
- '**.swift'

jobs:
use-qemu-user-static:
runs-on: ubuntu-${{ matrix.ubuntu_version }}
strategy:
fail-fast: false
matrix:
ubuntu_version:
- '20.04'
- '22.04' # latest
- '24.04'

steps:
- uses: actions/checkout@v4

- run: sudo apt-get update && sudo apt-get install -y qemu-user-static

- uses: ./.github/actions/configure-docker-containerd-image-store
with:
USE_CONTAINERD: true

- name: build arm64 architecture
uses: docker/build-push-action@v5
with:
load: true
platforms: linux/arm64
cache-from: type=gha
cache-to: type=gha,mode=max

use-qemu-user-static-from_debian:
name: qemu-user-static from debian ${{ matrix.target_release }}
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
target_release:
- 'buster' # 1:3.1+dfsg-8+deb10u12
- 'bullseye' # 1:5.2+dfsg-11+deb11u3
- 'bullseye-backports' # 1:7.2+dfsg-7+deb12u2~bpo11+1
- 'bookworm' # 1:7.2+dfsg-7+deb12u6
- 'bookworm-backports' # 1:8.2.1+ds-1~bpo12+1
- 'trixie' # 1:8.2.4+ds-1
- 'sid' # 1:9.0.1+ds-1

steps:
- uses: actions/checkout@v4

- uses: ./.github/actions/install_qemu_user_static_from_debian
with:
TARGET_RELEASE: ${{ matrix.target_release }}

- uses: ./.github/actions/configure-docker-containerd-image-store
with:
USE_CONTAINERD: true

- name: build arm64 architecture
uses: docker/build-push-action@v5
with:
load: true
platforms: linux/arm64
cache-from: type=gha
cache-to: type=gha,mode=max

use-tonistiigi_binfmt:
name: tonistiigi/binfmt:${{ matrix.tag }}
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
tag:
- latest
- qemu-v5.0.1
- qemu-v5.1.0
- qemu-v5.2.0
- qemu-v6.0.0
- qemu-v6.1.0
- qemu-v6.2.0
- qemu-v7.0.0 # latest
- qemu-v8.0.4
- qemu-v8.1.4
- qemu-v8.1.5

steps:
- uses: actions/checkout@v4

- uses: docker/setup-qemu-action@v3
with:
image: tonistiigi/binfmt:${{ matrix.tag }}
platforms: linux/arm64

- uses: ./.github/actions/configure-docker-containerd-image-store
with:
USE_CONTAINERD: true

- name: build arm64 architecture
uses: docker/build-push-action@v5
with:
load: true
platforms: linux/arm64
cache-from: type=gha
cache-to: type=gha,mode=max

use-multiarch_qemu-user-static:
name: multiarch/qemu-user-static:${{ matrix.tag }}
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
tag:
- latest
- 3.1.1-2
- 4.0.0-5
- 4.1.1-1
- 4.2.0-7
- 5.0.0-5
- 5.1.0-8
- 5.2.0-2
- 6.1.0-8
- 7.0.0-7
- 7.1.0-2
- 7.2.0-1 # latest

steps:
- uses: actions/checkout@v4

- run: docker run --rm --privileged multiarch/qemu-user-static:${{ matrix.tag }} --reset -p yes

- uses: ./.github/actions/configure-docker-containerd-image-store
with:
USE_CONTAINERD: true

- name: build arm64 architecture
uses: docker/build-push-action@v5
with:
load: true
platforms: linux/arm64
cache-from: type=gha
cache-to: type=gha,mode=max
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
.DS_Store
/.build
/Packages
xcuserdata/
DerivedData/
.swiftpm/configuration/registries.json
.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata
.netrc
12 changes: 12 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# syntax=docker/dockerfile:1

FROM swift:5.10
WORKDIR /app
COPY Sources /app/Sources
COPY Package.* /app
ARG TARGETPLATFORM
RUN --mount=type=cache,target=/app/.build,sharing=locked,id=${TARGETPLATFORM} \
swift build -c release --product hello-world && \
install $(swift build -c release --show-bin-path)/hello-world /usr/local/bin
RUN hello-world
CMD ["hello-world"]
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2024 Norio Nomura

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
15 changes: 15 additions & 0 deletions Package.resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"originHash" : "b9c47443daa3387adc9a9861ff912dd4f4dd9e850890e71c076288cde75316e7",
"pins" : [
{
"identity" : "swift-argument-parser",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-argument-parser.git",
"state" : {
"revision" : "0fbc8848e389af3bb55c182bc19ca9d5dc2f255b",
"version" : "1.4.0"
}
}
],
"version" : 3
}
24 changes: 24 additions & 0 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// swift-tools-version: 5.10
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription

let package = Package(
name: "hello-world",
products: [
.executable(name: "hello-world", targets: ["hello-world"]),
],
dependencies: [
.package(url: "https://github.com/apple/swift-argument-parser.git", from: "1.2.1"),
],
targets: [
// Targets are the basic building blocks of a package, defining a module or a test suite.
// Targets can depend on other targets in this package and products from dependencies.
.executableTarget(
name: "hello-world",
dependencies: [
.product(name: "ArgumentParser", package: "swift-argument-parser"),
]
),
]
)
25 changes: 25 additions & 0 deletions Sources/main.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import ArgumentParser

@main
struct Main: ParsableCommand {
static var configuration = CommandConfiguration(
commandName: "hello-world",
abstract: "A 'Hello, world!' program written in Swift.",
version: "1.0.0",
subcommands: [SayHello.self],
defaultSubcommand: SayHello.self
)
}

extension Main {
struct SayHello: ParsableCommand {
static var configuration = CommandConfiguration(
commandName: "say-hello",
abstract: "Prints 'Hello, world!' to the console."
)

func run() {
print("Hello, world!")
}
}
}

0 comments on commit 48fb005

Please sign in to comment.