Skip to content

Commit

Permalink
Enable local vscode dev container and install node, starship prompt t…
Browse files Browse the repository at this point in the history
…hrough Dockerfile (#9)

* feat: enable local vscode dev container and install through Dockerfile

* feat: update workflow build image

* Revert "feat: update workflow build image"

This reverts commit 911cc3a.

* feat: enable workflow auto build for dev image

* feat: pure prompt

---------

Co-authored-by: dependabot[bot] <dependabot[bot]@users.noreply.github.com>
  • Loading branch information
thangbuiq and dependabot[bot] authored Feb 9, 2024
1 parent 3ecca66 commit a4299fb
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 14,674 deletions.
19 changes: 11 additions & 8 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"image": "mcr.microsoft.com/devcontainers/base:ubuntu-22.04",
"name": "Ubunchuu Contributor",
"image": "ghcr.io/ubunchuu-truong-us/devcontainer:latest",
"customizations": {
"vscode": {
"settings": {
Expand Down Expand Up @@ -36,15 +37,17 @@
}
},
"forwardPorts": [3000],
"containerUser": "vscode",
"remoteUser": "vscode",
"postCreateCommand": "yarn install",
"postCreateCommand": "sudo chown vscode node_modules && rm -f package-lock.json || true && yarn install",
"waitFor": "postCreateCommand",
"postAttachCommand": "yarn start",
// "dockerFile": "${localWorkspaceFolder}/Dockerfile",
// "workspaceFolder": "/workspace/ubunchuu-contributor",
// "containerUser": "vscode",
// "mounts": [
// "source=${localWorkspaceFolderBasename}-node_modules,target=${containerWorkspaceFolder}/node_modules,type=volume",
// "source=./,target=/workspace/ubunchuu-contributor,type=bind,consistency=cached"
// ],
"features": {
"node": {
"version": "18"
},
"github-cli": "latest"
"ghcr.io/devcontainers/features/github-cli": "latest"
}
}
43 changes: 43 additions & 0 deletions .github/workflows/codespaces-image.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: Create and publish a Docker image

on:
push:
branches: ['main']
paths:
- Dockerfile

env:
USER: thangbuiq
REGISTRY: ghcr.io
IMAGE_NAME: ubunchuu-truong-us/devcontainer:latest

jobs:
build-and-push-image:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Log in to the Container registry
uses: docker/login-action@65b78e6e13532edd9afa3aa52ac7964289d1a9c1
with:
registry: ${{ env.REGISTRY }}
username: ${{ env.USER }}
password: ${{ secrets.TOKEN_GITHUB }}

- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}

- name: Build and push Docker image
uses: docker/build-push-action@f2a1d5e99d037542a71f64918e516c093c6f3fc4
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
26 changes: 26 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Use the base image
FROM mcr.microsoft.com/devcontainers/base:ubuntu-22.04

ARG DOCKERUSER=vscode
RUN \
echo '${DOCKERUSER} ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers && \
mkdir -p /home/${DOCKERUSER}/.local/bin /home/${DOCKERUSER}/.config && \
chown -R ${DOCKERUSER} /home/${DOCKERUSER}/

# Install Node.js 18
RUN \
apt-get update && apt-get install --no-install-recommends -y git curl sudo wget vim && \
curl -fsSL https://deb.nodesource.com/setup_18.x | bash - && \
apt-get update && apt-get install --no-install-recommends -y nodejs && \
apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*

# Install yarn
RUN \
npm install -g yarn

USER ${DOCKERUSER}

# Install starship for non-root user
RUN \
sh -c "$(curl -fsSL https://starship.rs/install.sh)" -- --yes -b /home/${DOCKERUSER}/.local/bin && \
echo 'eval "$(starship init bash && starship preset pure-preset -o ~/.config/starship.toml)"' >> /home/${DOCKERUSER}/.bashrc
Loading

0 comments on commit a4299fb

Please sign in to comment.