From 27cb0877ac6c9dbf66e3590988e4d90f606fcf5a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ph=E1=BA=A1m=20V=C4=83n=20Nguy=C3=AAn?= Date: Fri, 2 Feb 2024 09:06:03 +0700 Subject: [PATCH] feat: Add build-dev-container workflow and Ubuntu devcontainer - Added a new workflow file `build-dev-container.yaml` to build the development container. - Created a new devcontainer configuration file `devcontainer.json` for Ubuntu. - The workflow sets up a matrix based on subfolders in the templates directory. - The build step now uses the subfolder from the matrix to specify the template and image name. This commit adds support for building the development container and includes an initial configuration for Ubuntu. --- .github/workflows/build-dev-container.yaml | 24 ++++++++++++++++--- .../ubuntu/.devcontainer/devcontainer.json | 21 ++++++++++++++++ 2 files changed, 42 insertions(+), 3 deletions(-) create mode 100644 templates/ubuntu/.devcontainer/devcontainer.json diff --git a/.github/workflows/build-dev-container.yaml b/.github/workflows/build-dev-container.yaml index 9472e68..529987b 100644 --- a/.github/workflows/build-dev-container.yaml +++ b/.github/workflows/build-dev-container.yaml @@ -6,10 +6,28 @@ on: # rebuild any PRs and main branch changes - master jobs: - build: + prepare: runs-on: ubuntu-latest + outputs: + matrix: ${{ steps.set-matrix.outputs.matrix }} steps: + - name: Checkout (GitHub) + uses: actions/checkout@v3 + - name: Set matrix for build + id: set-matrix + run: | + FOLDERS=$(ls -d templates/*/) + FOLDERS=${FOLDERS//\//} # remove trailing slashes + FOLDERS=${FOLDERS//templates\//} # remove leading 'templates/' + FOLDERS_JSON=$(echo "$FOLDERS" | jq -R -s -c 'split("\n")[:-1]') + echo "::set-output name=matrix::${FOLDERS_JSON}" + build: + runs-on: ubuntu-latest + strategy: + matrix: + subfolder: ${{fromJson(needs.prepare.outputs.matrix)}} + steps: - name: Checkout uses: actions/checkout@v4 @@ -29,7 +47,7 @@ jobs: - name: Build and run Dev Container task uses: devcontainers/ci@v0.3 with: - subFolder: ./templates/react-native - imageName: ghcr.io/pnstack/codespace/react-native + subFolder: ./templates/${{ matrix.subfolder }} + imageName: ghcr.io/pnstack/codespace/${{ matrix.subfolder }} platform: linux/amd64,linux/arm64 push: always \ No newline at end of file diff --git a/templates/ubuntu/.devcontainer/devcontainer.json b/templates/ubuntu/.devcontainer/devcontainer.json new file mode 100644 index 0000000..6d44b5b --- /dev/null +++ b/templates/ubuntu/.devcontainer/devcontainer.json @@ -0,0 +1,21 @@ +// For format details, see https://aka.ms/devcontainer.json. For config options, see the +// README at: https://github.com/devcontainers/templates/tree/main/src/ubuntu +{ + "name": "Ubuntu", + // Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile + "image": "mcr.microsoft.com/devcontainers/base:jammy", + "runArgs": ["--device=/dev/net/tun"], + "features": {}, + + // Use 'forwardPorts' to make a list of ports inside the container available locally. + // "forwardPorts": [], + + // Use 'postCreateCommand' to run commands after the container is created. + // "postCreateCommand": "uname -a", + + // Configure tool-specific properties. + // "customizations": {}, + + // Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root. + "remoteUser": "root" +}