Skip to content

Commit

Permalink
First implementation of setup buildx action (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
n-g authored Mar 14, 2023
1 parent 2dda1d5 commit 57deadb
Show file tree
Hide file tree
Showing 13 changed files with 9,157 additions and 0 deletions.
35 changes: 35 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: e2e
on:
push:
branches:
- main
pull_request:
branches:
- "*"

permissions:
id-token: write # This is required for requesting the JWT
contents: read # This is required for actions/checkout

jobs:
build_and_push:
runs-on: ubuntu-latest
name: Build and push a sample application to Namespace Cloud
timeout-minutes: 5
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Set up Namespace Cloud CLI
id: nscloud
uses: namespacelabs/[email protected]
- name: Configure buildx
uses: ./ # Uses an action in the root directory
- name: Build and push
uses: docker/build-push-action@v4
with:
context: .
file: .github/workflows/testdata/Dockerfile
push: ${{ github.ref_name == 'main' }}
tags: "${{ steps.nscloud.outputs.registry-address }}/nscloud-setup-buildx-action/testdata/server:latest"
cache-from: "type=registry,ref=${{ steps.nscloud.outputs.registry-address }}/nscloud-setup-buildx-action/testdata/server:buildcache"
cache-to: "type=registry,ref=${{ steps.nscloud.outputs.registry-address }}/nscloud-setup-buildx-action/testdata/server:buildcache,mode=max"
2 changes: 2 additions & 0 deletions .github/workflows/testdata/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
FROM alpine:3.17.2
CMD ["echo", "Hello Namespace!"]
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules/
34 changes: 34 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Create a Namespace Cloud cluster

This repository hosts a GitHub action that configures buildx to use a
[Namespace Cloud](https://cloud.namespace.so) build cluster.

## Example

```yaml
jobs:
docker:
runs-on: ubuntu-latest
# These permissions are needed to interact with GitHub's OIDC Token endpoint.
permissions:
id-token: write
contents: read
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Install and configure Namespace Cloud CLI
uses: namespacelabs/[email protected]
- name: Configure buildx
uses: namespacelabs/[email protected]
- name: Build and push
uses: docker/build-push-action@v4
with:
push: true
tags: user/app:latest
```
## Requirements
This action uses `nsc`, the Namespace Cloud CLI.
You can add it to your workflow using [namespacelabs/nscloud-setup](https://github.com/namespacelabs/nscloud-setup)
(see [example](#example)).
7 changes: 7 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
name: '"Configure buildx with Namespace Cloud" Action For GitHub Actions'
description: "Configure buildx to use the Namespace Cloud build cluster"

runs:
using: node16
main: dist/main/index.js
post: dist/post/index.js
14 changes: 14 additions & 0 deletions common.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import * as path from "path";
import * as fs from "fs";

export const SessionId = "NscBuildkitProxySession";

export function tmpFile(file: string): string {
const tmpDir = path.join(process.env.RUNNER_TEMP, "ns");

if (!fs.existsSync(tmpDir)) {
fs.mkdirSync(tmpDir);
}

return path.join(tmpDir, file);
}
Loading

0 comments on commit 57deadb

Please sign in to comment.