Skip to content

Commit 3b63a7f

Browse files
authored
Merge pull request #10 from usma0118/devcontainers-template
Create devcontainer.yaml
2 parents 3c5b74a + 096fabb commit 3b63a7f

File tree

5 files changed

+230
-0
lines changed

5 files changed

+230
-0
lines changed

.devcontainer/base/.dockerignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
.git
2+
.vscode

.devcontainer/base/Dockerfile

+73
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
FROM mcr.microsoft.com/devcontainers/base:alpine-3.19
2+
ENV PYTHONUNBUFFERED 1
3+
ARG USERNAME=vscode
4+
5+
RUN apk add --no-cache \
6+
zsh \
7+
ca-certificates curl wget gettext sshpass \
8+
fzf jq git openssh-client \
9+
go-task \
10+
python3 py3-pip py3-virtualenv\
11+
git direnv shellcheck\
12+
ansible ansible-lint &&\
13+
apk add --no-cache \
14+
--repository=https://dl-cdn.alpinelinux.org/alpine/edge/community \
15+
age helm kubectl sops &&\
16+
apk add --no-cache \
17+
--repository=https://dl-cdn.alpinelinux.org/alpine/edge/testing \
18+
lsd
19+
RUN if [ -f /etc/bash.bashrc ]; then \
20+
echo -e 'eval "$(direnv hook bash)"' >> /etc/bash.bashrc; \
21+
fi && \
22+
if [ -f /etc/zsh/zshrc ]; then \
23+
echo -e 'eval "$(direnv hook zsh)"' >> /etc/zsh/zshrc; \
24+
fi
25+
USER $USERNAME
26+
27+
# Add direnv whitelist for the workspace directory
28+
RUN mkdir -p /home/$USERNAME/.config/direnv &&\
29+
chown -R $USERNAME:$USERNAME /home/$USERNAME/.config &&\
30+
tee /home/$USERNAME/.config/direnv/direnv.toml > /dev/null <<EOF
31+
[whitelist]
32+
prefix = [ "/workspaces", "/home/vscode/.dotfiles" ]
33+
EOF
34+
35+
WORKDIR /workspaces
36+
RUN virtualenv /home/$USERNAME/.venv &&\
37+
git config --global --add safe.directory /workspaces/dotfiles &&\
38+
git config --global --add safe.directory /home/$USERNAME/.dotfiles
39+
ENV VIRTUAL_ENV /home/$USERNAME/.venv
40+
ENV PATH $VIRTUAL_ENV:$PATH
41+
RUN . $VIRTUAL_ENV/bin/activate && pip install --upgrade pip && pip install pre-commit
42+
RUN mkdir /home/$USERNAME/.fonts \
43+
# Download MesloLGS font files
44+
&& curl -sLo /home/$USERNAME/.fonts/MesloLGS\ NF\ Regular.ttf https://github.com/romkatv/powerlevel10k-media/raw/master/MesloLGS%20NF%20Regular.ttf \
45+
&& curl -sLo /home/$USERNAME/.fonts/MesloLGS\ NF\ Bold.ttf https://github.com/romkatv/powerlevel10k-media/raw/master/MesloLGS%20NF%20Bold.ttf \
46+
&& curl -sLo /home/$USERNAME/.fonts/MesloLGS\ NF\ Italic.ttf https://github.com/romkatv/powerlevel10k-media/raw/master/MesloLGS%20NF%20Italic.ttf \
47+
&& curl -sLo /home/$USERNAME/.fonts/MesloLGS\ NF\ Bold\ Italic.ttf https://github.com/romkatv/powerlevel10k-media/raw/master/MesloLGS%20NF%20Bold%20Italic.ttf \
48+
# Download zsh-syntax-highlighting
49+
&& git clone https://github.com/zsh-users/zsh-syntax-highlighting.git /home/$USERNAME/.oh-my-zsh/custom/plugins/zsh-syntax-highlighting --depth 1 \
50+
# Download zsh-autosuggestions
51+
&& git clone https://github.com/zsh-users/zsh-autosuggestions /home/$USERNAME/.oh-my-zsh/custom/plugins/zsh-autosuggestions --depth 1 \
52+
# Download powerlevel10k
53+
&& git clone https://github.com/romkatv/powerlevel10k.git /home/$USERNAME/.oh-my-zsh/custom/themes/powerlevel10k --depth=1 \
54+
# Download powerlevel10k config
55+
&& curl -sLo /home/$USERNAME/.p10k.zsh https://raw.githubusercontent.com/usma0118/dotfiles/HEAD/zshrc/themes/dev.p10k.zsh \
56+
&& curl -sLo /home/$USERNAME/.zsh https://raw.githubusercontent.com/usma0118/dotfiles/HEAD/.profile/.zshrc \
57+
&& curl -sLo /home/$USERNAME/.aliases https://raw.githubusercontent.com/usma0118/dotfiles/HEAD/.profile/.aliases
58+
59+
RUN mkdir -p /home/$USERNAME/.vscode-server/extensions \
60+
/home/$USERNAME/.cache \
61+
/home/$USERNAME/.local \
62+
/home/$USERNAME/.history \
63+
&& chown -R $USERNAME \
64+
/home/$USERNAME/.vscode-server \
65+
/home/$USERNAME/.cache \
66+
/home/$USERNAME/.local \
67+
/home/$USERNAME/.history \
68+
/home/$USERNAME/.oh-my-zsh/custom/themes \
69+
/home/$USERNAME/.oh-my-zsh/custom/plugins &&\
70+
SNIPPET="export PROMPT_COMMAND='history -a' && export HISTFILE=/home/$USERNAME/.history/.bash_history" >> "/home/$USERNAME/.bashrc" &&\
71+
echo "export PROMPT_COMMAND='history -a' && export HISTFILE=/home/$USERNAME/.history/.zsh_history" >> "/home/$USERNAME/.zsh_history"
72+
73+
RUN echo "Pre-Loading zsh" && zsh -i -c "exit"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
---
2+
# yaml-language-server: $schema=https://json.schemastore.org/github-workflow.json
3+
name: "Dev container - Build & release"
4+
on:
5+
workflow_dispatch:
6+
inputs:
7+
logLevel:
8+
description: 'Log level'
9+
required: true
10+
default: 'warning'
11+
type: choice
12+
options:
13+
- info
14+
- warning
15+
- debug
16+
push:
17+
branches: ["main"]
18+
tags:
19+
- '**'
20+
paths: [".devcontainer/base/**"]
21+
pull_request:
22+
branches: ["main"]
23+
paths: [".devcontainer/base/**"]
24+
concurrency:
25+
group: ${{ github.workflow }}-${{ github.event.number || github.ref }}
26+
cancel-in-progress: true
27+
env:
28+
REGISTRY: ghcr.io
29+
IMAGE_NAME: ${{ github.repository }}/devcontainers/base
30+
jobs:
31+
build-docker-image:
32+
runs-on: ubuntu-latest
33+
permissions:
34+
contents: read
35+
packages: write
36+
id-token: write
37+
attestations: write
38+
strategy:
39+
fail-fast: true
40+
steps:
41+
- uses: actions/checkout@v4
42+
- name: Set up QEMU
43+
uses: docker/setup-qemu-action@v3
44+
with:
45+
platforms: arm64,amd64,arm
46+
- name: Set up Docker Buildx
47+
uses: docker/setup-buildx-action@v3
48+
with:
49+
install: true
50+
- if: ${{ github.event_name != 'pull_request' }}
51+
name: Login to GitHub Container Registry
52+
uses: docker/login-action@v3
53+
with:
54+
registry: ${{ env.REGISTRY }}
55+
username: ${{ github.actor }}
56+
password: ${{ secrets.GITHUB_TOKEN }}
57+
- name: Extract metadata (tags, labels) for Docker
58+
id: meta
59+
uses: docker/metadata-action@f7b4ed12385588c3f9bc252f0a2b520d83b52d48
60+
with:
61+
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
62+
tags: |
63+
type=semver,pattern={{version}}
64+
type=semver,pattern={{major}}.{{minor}}
65+
type=sha,format=short
66+
flavor: |
67+
latest=auto
68+
prefix=
69+
suffix=
70+
- name: Build and push
71+
id: docker_build
72+
uses: docker/build-push-action@v5
73+
with:
74+
context: "{{defaultContext}}:cryfs"
75+
sbom: true
76+
platforms: linux/amd64,linux/arm64
77+
push: ${{ github.event_name != 'pull_request' }}
78+
tags: ${{ steps.meta.outputs.tags }}
79+
labels: ${{ steps.meta.outputs.labels }}
80+
cache-from: |
81+
type=gha
82+
cache-to: type=gha,mode=max
83+
- if: ${{ github.event_name != 'pull_request' }}
84+
name: Generate artifact attestation
85+
uses: actions/attest-build-provenance@v1
86+
id: attest
87+
with:
88+
subject-name: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME}}
89+
subject-digest: ${{ steps.docker_build.outputs.digest }}
90+
push-to-registry: ${{ github.event_name != 'pull_request' }}

.github/workflows/devcontainer.yaml

+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
---
2+
# yaml-language-server: $schema=https://json.schemastore.org/github-workflow.json
3+
name: "Devcontainer"
4+
5+
on:
6+
workflow_dispatch:
7+
push:
8+
branches: ["main"]
9+
paths: ["devcontainer/**"]
10+
pull_request:
11+
branches: ["main"]
12+
paths: ["devcontainer/**"]
13+
# schedule:
14+
# - cron: "0 0 * * 1"
15+
16+
concurrency:
17+
group: ${{ github.workflow }}-${{ github.event.number || github.ref }}
18+
cancel-in-progress: true
19+
20+
jobs:
21+
devcontainer:
22+
if: ${{ github.repository == 'usma0118/containers/devcontainers' }}
23+
name: publish
24+
runs-on: ubuntu-latest
25+
permissions:
26+
contents: read
27+
packages: write
28+
steps:
29+
- name: Checkout
30+
uses: actions/checkout@v4
31+
32+
- name: Set up QEMU
33+
uses: docker/setup-qemu-action@v3
34+
35+
- name: Set up Docker Buildx
36+
uses: docker/setup-buildx-action@v3
37+
with:
38+
platforms: linux/amd64,linux/arm64
39+
40+
- if: ${{ github.event_name != 'pull_request' }}
41+
name: Login to GitHub Container Registry
42+
uses: docker/login-action@v3
43+
with:
44+
registry: ghcr.io
45+
username: ${{ github.actor }}
46+
password: ${{ secrets.GITHUB_TOKEN }}
47+
48+
- name: Build and push
49+
uses: devcontainers/ci@v0.3
50+
env:
51+
BUILDX_NO_DEFAULT_ATTESTATIONS: true
52+
with:
53+
imageName: ghcr.io/${{ github.repository }}/devcontainer
54+
# cacheFrom: ghcr.io/${{ github.repository }}/devcontainer
55+
imageTag: base,latest
56+
platform: linux/amd64,linux/arm64
57+
configFile: devcontainer/dev/devcontainer.json
58+
push: ${{ github.event_name == 'pull_request' && 'never' || 'always' }}

.vscode/settings.json

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"ansible.python.interpreterPath": "/home/vscode/.venv/bin/python",
3+
"terminal.integrated.fontFamily": "MesloLGS NF",
4+
"dotfiles.repository": "usma0118/dotfiles",
5+
"dotfiles.targetPath": "~/.dotfiles",
6+
"dotfiles.installCommand": "~/.dotfiles/bootstrap.sh",
7+
}

0 commit comments

Comments
 (0)