Skip to content

Commit 2b21194

Browse files
committed
first
0 parents  commit 2b21194

15 files changed

Lines changed: 589 additions & 0 deletions

File tree

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
name: 'Docker Build Action'
2+
description: 'Builds a Docker image using a specified Dockerfile and context'
3+
4+
inputs:
5+
context:
6+
description: 'The Docker build context (path to the directory containing the Dockerfile)'
7+
required: true
8+
default: '.'
9+
dockerfile:
10+
description: 'The path to the Dockerfile (relative to the context)'
11+
required: true
12+
default: 'Dockerfile'
13+
build-arg-version-name:
14+
description: 'The name of the build argument'
15+
required: true
16+
build-arg-version-value:
17+
description: 'The value of the build argument'
18+
required: true
19+
tag:
20+
description: 'The tag to use for the image'
21+
required: true
22+
image-name:
23+
description: 'The name of the image to build'
24+
required: true
25+
push:
26+
description: 'Determines if the built image should be pushed'
27+
required: true
28+
default: 'no'
29+
container-registry:
30+
description: 'container registry address (example: ghcr.io)'
31+
required: false
32+
container-registry-username:
33+
description: 'container registry username'
34+
required: false
35+
container-registry-password:
36+
description: 'container registry password'
37+
required: false
38+
39+
runs:
40+
using: 'composite'
41+
42+
steps:
43+
- name: Checkout
44+
uses: actions/checkout@v4
45+
46+
- name: Login to GitHub Container Registry
47+
uses: docker/login-action@v3
48+
if: ${{ inputs.push == 'true' }}
49+
with:
50+
logout: false
51+
registry: ${{ inputs.container-registry }}
52+
username: ${{ inputs.container-registry-username }}
53+
password: ${{ inputs.container-registry-password }}
54+
55+
- name: Set up QEMU
56+
uses: docker/setup-qemu-action@v3
57+
58+
- name: Set up Docker Buildx
59+
uses: docker/setup-buildx-action@v3
60+
61+
- name: Extract metadata (tags, labels) for Docker image
62+
id: meta
63+
uses: docker/metadata-action@v5
64+
with:
65+
images: |
66+
${{ inputs.container-registry }}/${{ github.repository_owner }}/${{ inputs.image-name }}
67+
tags: |
68+
type=raw,enable={{is_default_branch}},value=${{ inputs.tag }},priority=300
69+
type=raw,enable={{is_default_branch}},value=${{ inputs.tag-latest }},priority=300
70+
71+
- name: Build image and push (optional)
72+
uses: docker/build-push-action@v6
73+
with:
74+
platforms: linux/amd64,linux/arm64
75+
push: ${{ inputs.push == 'true' }}
76+
context: ${{ inputs.context }}
77+
file: ${{ inputs.dockerfile }}
78+
tags: ${{ steps.meta.outputs.tags }}
79+
labels: ${{ steps.meta.outputs.labels }}
80+
build-args: |
81+
${{ inputs.build-arg-version-name }}=${{ inputs.build-arg-version-value }}

.github/workflows/go.yaml

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
name: Go Blueprints CI and CD
2+
3+
on:
4+
push:
5+
paths:
6+
- 'go/**'
7+
8+
pull_request:
9+
paths:
10+
- 'go/**'
11+
12+
env:
13+
REGISTRY: ghcr.io
14+
IMAGE_NAME: code-runner
15+
BUILD_ARG_VERSION_NAME: GO_VERSION
16+
concurrency:
17+
group: go-${{ github.ref }}
18+
cancel-in-progress: true
19+
20+
jobs:
21+
ci:
22+
runs-on: ubuntu-latest
23+
24+
strategy:
25+
matrix:
26+
go_version: [1.23, 1.24]
27+
28+
steps:
29+
- name: Checkout code
30+
uses: actions/checkout@v4
31+
32+
- name: Build go:${{ matrix.go_version }} image
33+
uses: ./.github/actions/docker-build
34+
with:
35+
context: ./go
36+
dockerfile: ./go/Dockerfile
37+
image-name: ${{ env.IMAGE_NAME }}
38+
push: false
39+
container-registry: ${{ env.REGISTRY }}
40+
build-arg-version-name: ${{ env.BUILD_ARG_VERSION_NAME }}
41+
build-arg-version-value: ${{ matrix.go_version }}
42+
43+
cd:
44+
runs-on: ubuntu-latest
45+
46+
if: ${{ format('refs/heads/{0}', github.event.repository.default_branch) == github.ref }}
47+
48+
strategy:
49+
matrix:
50+
go_version: [1.23, 1.24]
51+
52+
permissions:
53+
packages: write
54+
contents: read
55+
56+
needs:
57+
- ci
58+
59+
steps:
60+
- name: Checkout code
61+
uses: actions/checkout@v4
62+
63+
- name: Build and push go:${{ matrix.go_version }} image
64+
uses: ./.github/actions/docker-build
65+
with:
66+
context: ./go
67+
dockerfile: ./go/Dockerfile
68+
image-name: ${{ env.IMAGE_NAME }}
69+
tag: go-${{ matrix.go_version }}
70+
push: true
71+
container-registry: ${{ env.REGISTRY }}
72+
container-registry-username: ${{ github.actor }}
73+
container-registry-password: ${{ secrets.GITHUB_TOKEN }}
74+
build-arg-version-name: ${{ env.BUILD_ARG_VERSION_NAME }}
75+
build-arg-version-value: ${{ matrix.go_version }}

.github/workflows/nodejs.yaml

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
name: NodeJS Blueprints CI and CD
2+
3+
on:
4+
push:
5+
paths:
6+
- 'nodejs/**'
7+
8+
pull_request:
9+
paths:
10+
- 'nodejs/**'
11+
12+
env:
13+
REGISTRY: ghcr.io
14+
IMAGE_NAME: code-runner
15+
BUILD_ARG_VERSION_NAME: NODEJS_VERSION
16+
17+
concurrency:
18+
group: nodejs-${{ github.ref }}
19+
cancel-in-progress: true
20+
21+
jobs:
22+
ci:
23+
runs-on: ubuntu-latest
24+
25+
strategy:
26+
matrix:
27+
nodejs_version: [20.19, 22.14, 23.11]
28+
29+
steps:
30+
- name: Checkout code
31+
uses: actions/checkout@v4
32+
33+
- name: Build nodejs:${{ matrix.nodejs_version }} image
34+
uses: ./.github/actions/docker-build
35+
with:
36+
context: ./nodejs
37+
dockerfile: ./nodejs/Dockerfile
38+
image-name: ${{ env.IMAGE_NAME }}
39+
push: false
40+
container-registry: ${{ env.REGISTRY }}
41+
build-arg-version-name: ${{ env.BUILD_ARG_VERSION_NAME }}
42+
build-arg-version-value: ${{ matrix.nodejs_version }}
43+
44+
cd:
45+
runs-on: ubuntu-latest
46+
47+
if: ${{ format('refs/heads/{0}', github.event.repository.default_branch) == github.ref }}
48+
49+
strategy:
50+
matrix:
51+
nodejs_version: [20.19, 22.14, 23.11]
52+
53+
permissions:
54+
packages: write
55+
contents: read
56+
57+
needs:
58+
- ci
59+
60+
steps:
61+
- name: Checkout code
62+
uses: actions/checkout@v4
63+
64+
- name: Build and push nodejs:${{ matrix.nodejs_version }} image
65+
uses: ./.github/actions/docker-build
66+
with:
67+
context: ./nodejs
68+
dockerfile: ./nodejs/Dockerfile
69+
image-name: ${{ env.IMAGE_NAME }}
70+
tag: nodejs-${{ matrix.nodejs_version }}
71+
push: true
72+
container-registry: ${{ env.REGISTRY }}
73+
container-registry-username: ${{ github.actor }}
74+
container-registry-password: ${{ secrets.GITHUB_TOKEN }}
75+
build-arg-version-name: ${{ env.BUILD_ARG_VERSION_NAME }}
76+
build-arg-version-value: ${{ matrix.nodejs_version }}

.github/workflows/php.yaml

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
name: PHP Blueprints CI and CD
2+
3+
on:
4+
push:
5+
paths:
6+
- 'php/**'
7+
8+
pull_request:
9+
paths:
10+
- 'php/**'
11+
12+
env:
13+
REGISTRY: ghcr.io
14+
IMAGE_NAME: code-runner
15+
BUILD_ARG_VERSION_NAME: PHP_VERSION
16+
17+
concurrency:
18+
group: php-${{ github.ref }}
19+
cancel-in-progress: true
20+
21+
jobs:
22+
ci:
23+
runs-on: ubuntu-latest
24+
25+
strategy:
26+
matrix:
27+
php_version: [8.3, 8.4]
28+
29+
steps:
30+
- name: Checkout code
31+
uses: actions/checkout@v4
32+
33+
- name: Build php:${{ matrix.php_version }} image
34+
uses: ./.github/actions/docker-build
35+
with:
36+
context: ./php
37+
dockerfile: ./php/Dockerfile
38+
image-name: ${{ env.IMAGE_NAME }}
39+
push: false
40+
container-registry: ${{ env.REGISTRY }}
41+
build-arg-version-name: ${{ env.BUILD_ARG_VERSION_NAME }}
42+
build-arg-version-value: ${{ matrix.php_version }}
43+
44+
cd:
45+
runs-on: ubuntu-latest
46+
47+
if: ${{ format('refs/heads/{0}', github.event.repository.default_branch) == github.ref }}
48+
49+
strategy:
50+
matrix:
51+
php_version: [8.3, 8.4]
52+
53+
permissions:
54+
packages: write
55+
contents: read
56+
57+
needs:
58+
- ci
59+
60+
steps:
61+
- name: Checkout code
62+
uses: actions/checkout@v4
63+
64+
- name: Build and push php:${{ matrix.php_version }} image
65+
uses: ./.github/actions/docker-build
66+
with:
67+
context: ./php
68+
dockerfile: ./php/Dockerfile
69+
image-name: ${{ env.IMAGE_NAME }}
70+
tag: php-${{ matrix.php_version }}
71+
push: true
72+
container-registry: ${{ env.REGISTRY }}
73+
container-registry-username: ${{ github.actor }}
74+
container-registry-password: ${{ secrets.GITHUB_TOKEN }}
75+
build-arg-version-name: ${{ env.BUILD_ARG_VERSION_NAME }}
76+
build-arg-version-value: ${{ matrix.php_version }}

.gitignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
.DS_Store
2+
.vscode
3+
.idea
4+
5+
/private
6+
/private.pub
7+
/tmp

go/Dockerfile

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Accept Go version as build argument
2+
ARG GO_VERSION=1.24
3+
4+
FROM golang:${GO_VERSION}-alpine
5+
6+
RUN apk add --no-cache bash coreutils
7+
8+
WORKDIR /app
9+
10+
COPY run.sh /run.sh
11+
RUN chmod +x /run.sh
12+
13+
ENTRYPOINT ["/run.sh"]

go/readme.md

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
This Dockerfile will creates a docker image which can be used to run a go code with a timeout.
2+
3+
# How to build
4+
5+
```
6+
# building with go 1.24
7+
docker build --build-arg GO_VERSION=1.24 -t go-code-runner:1.24 .
8+
9+
# building with go 1.23
10+
docker build --build-arg GO_VERSION=1.23 -t go-code-runner:1.23 .
11+
```
12+
13+
The Go version can be specified by passing the `GO_VERSION` argument to the `docker build` command.
14+
15+
# How to use
16+
17+
1. Run code with default timeout
18+
19+
```sh
20+
docker run --rm go-code-runner:1.23 'package main; import("fmt"); func main() { fmt.Println("Hello!") }'
21+
```
22+
23+
2. Run code with custom timeout
24+
25+
```sh
26+
docker run --rm go-code-runner:1.24 --timeout 3 'package main; import("time"); func main() { time.Sleep(5 * time.Second) }'
27+
```
28+
29+
3. Multiline + custom timeout
30+
31+
```sh
32+
docker run --rm -i go-code-runner:1.24 --timeout 5 <<EOF
33+
package main
34+
35+
import (
36+
"fmt"
37+
"time"
38+
)
39+
40+
func main() {
41+
for i := 0; i < 10; i++ {
42+
fmt.Println("Tick", i)
43+
time.Sleep(time.Second)
44+
}
45+
}
46+
EOF
47+
```

0 commit comments

Comments
 (0)