Skip to content

Commit

Permalink
Merge pull request #11 from railwayapp/jr/pro-3696-image-build-and-co…
Browse files Browse the repository at this point in the history
…ntainer-run-tests

image run tests
  • Loading branch information
coffee-cup authored Feb 6, 2025
2 parents 8edbee1 + c16ce3a commit c1a5339
Show file tree
Hide file tree
Showing 19 changed files with 345 additions and 197 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,5 @@ jobs:
- name: Vet
run: go vet ./...

- name: Test
run: go test ./...
- name: Test Unit
run: go test -short ./...
70 changes: 70 additions & 0 deletions .github/workflows/run_tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
name: Run Tests

on:
push:
branches: [main]
pull_request:
branches: [main]

jobs:
find-examples:
runs-on: ubuntu-latest
outputs:
examples: ${{ steps.find-examples.outputs.examples }}
steps:
- uses: actions/checkout@v4

- name: Find examples with test.json
id: find-examples
run: |
examples=$(find examples -name "test.json" -exec dirname {} \; | xargs -n 1 basename | jq -R -s -c 'split("\n")[:-1]')
echo "examples=$examples" >> "$GITHUB_OUTPUT"
test:
needs: find-examples
runs-on: ubuntu-latest
strategy:
matrix:
example: ${{ fromJson(needs.find-examples.outputs.examples) }}
fail-fast: false

steps:
- uses: actions/checkout@v4

- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: "1.23.4"
cache: true

# Set up GitHub Actions runtime for BuildKit cache
- name: Set up BuildKit GHA cache
uses: crazy-max/ghaction-github-runtime@v3

- name: Start BuildKit
run: |
docker run --rm --privileged -d \
--name buildkit \
-e BUILDKIT_DEBUG=1 \
moby/buildkit:latest
# Wait for BuildKit to be ready
sleep 5
echo "BUILDKIT_HOST=docker-container://buildkit" >> $GITHUB_ENV
- name: Install dependencies
run: go mod download

- name: Run test for ${{ matrix.example }}
run: |
# Add cache import/export flags to the test command
go test -v ./integration_tests \
-run "TestExamplesIntegration/${{ matrix.example }}" \
-timeout 30m \
-buildkit-cache-import="type=gha,url=${{ env.ACTIONS_CACHE_URL }},token=${{ env.ACTIONS_RUNTIME_TOKEN }},scope=${{ matrix.example }}" \
-buildkit-cache-export="type=gha,url=${{ env.ACTIONS_CACHE_URL }},token=${{ env.ACTIONS_RUNTIME_TOKEN }},mode=max,scope=${{ matrix.example }}"
- name: Stop BuildKit
if: always()
run: docker stop buildkit
31 changes: 31 additions & 0 deletions buildkit/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ type BuildWithBuildkitClientOptions struct {
SecretsHash string
Secrets map[string]string
Platform BuildPlatform
ImportCache string
ExportCache string
}

func BuildWithBuildkitClient(appDir string, plan *plan.BuildPlan, opts BuildWithBuildkitClientOptions) error {
Expand Down Expand Up @@ -176,6 +178,22 @@ func BuildWithBuildkitClient(appDir string, plan *plan.BuildPlan, opts BuildWith
},
}

// Add cache import if specified
if opts.ImportCache != "" {
solveOpts.CacheImports = append(solveOpts.CacheImports, client.CacheOptionsEntry{
Type: "gha",
Attrs: parseKeyValue(opts.ImportCache),
})
}

// Add cache export if specified
if opts.ExportCache != "" {
solveOpts.CacheExports = append(solveOpts.CacheExports, client.CacheOptionsEntry{
Type: "gha",
Attrs: parseKeyValue(opts.ExportCache),
})
}

// Save the resulting filesystem to a directory
if opts.OutputDir != "" {
err = os.MkdirAll(opts.OutputDir, 0755)
Expand Down Expand Up @@ -237,3 +255,16 @@ func getImageName(appDir string) string {
}
return name
}

// Helper function to parse key=value strings into a map
func parseKeyValue(s string) map[string]string {
attrs := make(map[string]string)
parts := strings.Split(s, ",")
for _, part := range parts {
kv := strings.SplitN(part, "=", 2)
if len(kv) == 2 {
attrs[kv[0]] = kv[1]
}
}
return attrs
}
198 changes: 6 additions & 192 deletions core/__snapshots__/core_test.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2831,10 +2831,6 @@
"apt-lists": {
"directory": "/var/lib/apt/lists",
"type": "locked"
},
"mise": {
"directory": "/mise/cache",
"type": "shared"
}
},
"start": {
Expand Down Expand Up @@ -2866,98 +2862,6 @@
"name": "packages:apt:nginx",
"useSecrets": false
},
{
"assets": {
"mise.toml": "[tools]\n [tools.node]\n version = \"23.7.0\"\n [tools.npm]\n version = \"11.1.0\"\n"
},
"commands": [
{
"name": "MISE_INSTALL_PATH",
"value": "/usr/local/bin/mise"
},
{
"name": "MISE_DATA_DIR",
"value": "/mise"
},
{
"name": "MISE_CONFIG_DIR",
"value": "/mise"
},
{
"name": "MISE_CACHE_DIR",
"value": "/mise/cache"
},
{
"path": "/mise/shims"
},
{
"caches": [
"apt",
"apt-lists"
],
"cmd": "sh -c 'apt-get update \u0026\u0026 apt-get install -y ca-certificates curl git'",
"customName": "install apt packages: ca-certificates curl git"
},
{
"caches": [
"mise"
],
"cmd": "sh -c 'curl -fsSL https://mise.run | sh'",
"customName": "install mise"
},
{
"customName": "create mise config",
"name": "mise.toml",
"path": "/etc/mise/config.toml"
},
{
"caches": [
"mise"
],
"cmd": "sh -c 'mise trust -a \u0026\u0026 mise install'",
"customName": "install mise packages: node, npm"
}
],
"dependsOn": [
"packages:image"
],
"name": "packages:mise",
"outputs": [
"/mise/shims",
"/mise/installs",
"/usr/local/bin/mise",
"/etc/mise/config.toml",
"/root/.local/state/mise"
],
"useSecrets": false
},
{
"commands": [
{
"name": "CI",
"value": "true"
},
{
"name": "NODE_ENV",
"value": "production"
},
{
"name": "NPM_CONFIG_PRODUCTION",
"value": "false"
},
{
"name": "YARN_PRODUCTION",
"value": "false"
},
{
"path": "/app/node_modules/.bin"
}
],
"dependsOn": [
"packages:mise"
],
"name": "setup:node"
},
{
"assets": {
"nginx.conf": "worker_processes 5;\ndaemon off;\n\nworker_rlimit_nofile 8192;\n\nevents {\n worker_connections 4096;\n}\n\nhttp {\n include /etc/nginx/mime.types;\n index index.html index.htm index.php;\n\n default_type application/octet-stream;\n log_format main '$remote_addr - $remote_user [$time_local] $status '\n '\"$request\" $body_bytes_sent \"$http_referer\" '\n '\"$http_user_agent\" \"$http_x_forwarded_for\"';\n\n access_log /dev/stdout;\n error_log /dev/stdout;\n sendfile on;\n tcp_nopush on;\n server_names_hash_bucket_size 128; # this seems to be required for some vhosts\n\n server {\n listen 0.0.0.0:80;\n listen [::]:80;\n\n server_name localhost;\n\n \n root /app;\n \n \n add_header X-Frame-Options \"SAMEORIGIN\";\n add_header X-Content-Type-Options \"nosniff\";\n \n index index.php;\n \n charset utf-8;\n \n \n \n \n \n location = /favicon.ico { access_log off; log_not_found off; }\n location = /robots.txt { access_log off; log_not_found off; }\n \n \n \n location ~ \\.php$ {\n fastcgi_pass 127.0.0.1:9000;\n fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;\n include /etc/nginx/fastcgi_params;\n include /etc/nginx/fastcgi.conf;\n }\n \n location ~ /\\.(?!well-known).* {\n deny all;\n }\n }\n}\n",
Expand Down Expand Up @@ -2989,6 +2893,9 @@
"packages:apt:nginx"
],
"name": "nginx:setup"
},
{
"name": "packages:mise"
}
]
}
Expand All @@ -3005,10 +2912,6 @@
"apt-lists": {
"directory": "/var/lib/apt/lists",
"type": "locked"
},
"mise": {
"directory": "/mise/cache",
"type": "shared"
}
},
"start": {
Expand Down Expand Up @@ -3060,98 +2963,6 @@
],
"name": "install"
},
{
"assets": {
"mise.toml": "[tools]\n [tools.node]\n version = \"23.7.0\"\n [tools.npm]\n version = \"11.1.0\"\n"
},
"commands": [
{
"name": "MISE_INSTALL_PATH",
"value": "/usr/local/bin/mise"
},
{
"name": "MISE_DATA_DIR",
"value": "/mise"
},
{
"name": "MISE_CONFIG_DIR",
"value": "/mise"
},
{
"name": "MISE_CACHE_DIR",
"value": "/mise/cache"
},
{
"path": "/mise/shims"
},
{
"caches": [
"apt",
"apt-lists"
],
"cmd": "sh -c 'apt-get update \u0026\u0026 apt-get install -y ca-certificates curl git'",
"customName": "install apt packages: ca-certificates curl git"
},
{
"caches": [
"mise"
],
"cmd": "sh -c 'curl -fsSL https://mise.run | sh'",
"customName": "install mise"
},
{
"customName": "create mise config",
"name": "mise.toml",
"path": "/etc/mise/config.toml"
},
{
"caches": [
"mise"
],
"cmd": "sh -c 'mise trust -a \u0026\u0026 mise install'",
"customName": "install mise packages: node, npm"
}
],
"dependsOn": [
"packages:image"
],
"name": "packages:mise",
"outputs": [
"/mise/shims",
"/mise/installs",
"/usr/local/bin/mise",
"/etc/mise/config.toml",
"/root/.local/state/mise"
],
"useSecrets": false
},
{
"commands": [
{
"name": "CI",
"value": "true"
},
{
"name": "NODE_ENV",
"value": "production"
},
{
"name": "NPM_CONFIG_PRODUCTION",
"value": "false"
},
{
"name": "YARN_PRODUCTION",
"value": "false"
},
{
"path": "/app/node_modules/.bin"
}
],
"dependsOn": [
"packages:mise"
],
"name": "setup:node"
},
{
"assets": {
"nginx.conf": "worker_processes 5;\ndaemon off;\n\nworker_rlimit_nofile 8192;\n\nevents {\n worker_connections 4096;\n}\n\nhttp {\n include /etc/nginx/mime.types;\n index index.html index.htm index.php;\n\n default_type application/octet-stream;\n log_format main '$remote_addr - $remote_user [$time_local] $status '\n '\"$request\" $body_bytes_sent \"$http_referer\" '\n '\"$http_user_agent\" \"$http_x_forwarded_for\"';\n\n access_log /dev/stdout;\n error_log /dev/stdout;\n sendfile on;\n tcp_nopush on;\n server_names_hash_bucket_size 128; # this seems to be required for some vhosts\n\n server {\n listen 0.0.0.0:80;\n listen [::]:80;\n\n server_name localhost;\n\n \n root /app;\n \n \n add_header X-Frame-Options \"SAMEORIGIN\";\n add_header X-Content-Type-Options \"nosniff\";\n \n index index.php;\n \n charset utf-8;\n \n \n \n \n \n location = /favicon.ico { access_log off; log_not_found off; }\n location = /robots.txt { access_log off; log_not_found off; }\n \n \n \n location ~ \\.php$ {\n fastcgi_pass 127.0.0.1:9000;\n fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;\n include /etc/nginx/fastcgi_params;\n include /etc/nginx/fastcgi.conf;\n }\n \n location ~ /\\.(?!well-known).* {\n deny all;\n }\n }\n}\n",
Expand Down Expand Up @@ -3183,6 +2994,9 @@
"packages:apt:nginx"
],
"name": "nginx:setup"
},
{
"name": "packages:mise"
}
]
}
Expand Down
1 change: 1 addition & 0 deletions core/mise/mise.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ func (m *Mise) runCmd(args ...string) (string, error) {
cmd.Env = append(cmd.Env,
fmt.Sprintf("MISE_CACHE_DIR=%s", cacheDir),
fmt.Sprintf("MISE_DATA_DIR=%s", dataDir),
"MISE_HTTP_TIMEOUT=120",
fmt.Sprintf("PATH=%s", os.Getenv("PATH")),
)

Expand Down
3 changes: 2 additions & 1 deletion core/providers/php/php.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ func (p *PhpProvider) Plan(ctx *generate.GenerateContext) error {

// Install node
nodeProvider := node.NodeProvider{}
if packageJson, err := nodeProvider.GetPackageJson(ctx.App); err == nil && packageJson != nil {
isNode := ctx.App.HasMatch("package.json")
if packageJson, err := nodeProvider.GetPackageJson(ctx.App); isNode && err == nil && packageJson != nil {
ctx.EnterSubContext("node")

nodePackages, err := nodeProvider.Packages(ctx, packageJson)
Expand Down
Loading

0 comments on commit c1a5339

Please sign in to comment.