Skip to content

Commit 2b71002

Browse files
authored
Better devcontainer (#4349)
1 parent 7e72c24 commit 2b71002

File tree

4 files changed

+107
-20
lines changed

4 files changed

+107
-20
lines changed

.devcontainer/Dockerfile

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# Use the same base image as the original devcontainer
2+
FROM mcr.microsoft.com/vscode/devcontainers/base:bullseye
3+
4+
# Install Microsoft OpenJDK 17 and Docker
5+
RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
6+
&& apt-get -y install --no-install-recommends \
7+
wget \
8+
ca-certificates \
9+
curl \
10+
gnupg \
11+
lsb-release \
12+
&& wget -q https://packages.microsoft.com/config/debian/11/packages-microsoft-prod.deb -O packages-microsoft-prod.deb \
13+
&& dpkg -i packages-microsoft-prod.deb \
14+
&& curl -fsSL https://download.docker.com/linux/debian/gpg | gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg \
15+
&& echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/debian $(lsb_release -cs) stable" | tee /etc/apt/sources.list.d/docker.list > /dev/null \
16+
&& apt-get update \
17+
&& apt-get -y install --no-install-recommends \
18+
msopenjdk-17 \
19+
docker-ce \
20+
docker-ce-cli \
21+
containerd.io \
22+
&& usermod -aG docker vscode `# Add vscode user to docker group for Docker access` \
23+
&& apt-get clean \
24+
&& rm -rf /var/lib/apt/lists/* \
25+
&& rm packages-microsoft-prod.deb
26+
27+
# Switch to vscode user for the build
28+
USER vscode
29+
30+
# Set working directory for build
31+
WORKDIR /tmp/build
32+
33+
# Copy all project files for the build
34+
COPY --chown=vscode:vscode . ./
35+
36+
# Pre-populate Gradle dependency and build caches by compiling all classes
37+
# Use --no-daemon to avoid leaving daemon processes running
38+
RUN export JAVA_HOME=/usr/lib/jvm/msopenjdk-17-amd64 && \
39+
export PATH="$JAVA_HOME/bin:$PATH" && \
40+
./gradlew classes --no-daemon
41+
42+
# Clean up the build directory but preserve gradle cache
43+
RUN rm -rf /tmp/build
44+
45+
# Set default working directory for development
46+
WORKDIR /workspaces

.devcontainer/devcontainer.json

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,12 @@
11
{
22
"name": "Application Insights Java Development Environment",
3-
"image": "mcr.microsoft.com/vscode/devcontainers/base:bullseye",
4-
"features": {
5-
"ghcr.io/devcontainers/features/java:1": {
6-
"version": "17"
7-
},
8-
"ghcr.io/devcontainers/features/docker-in-docker:2": {
9-
"version": "latest"
10-
}
11-
},
3+
"image": "ghcr.io/microsoft/applicationinsights-java/devcontainer:latest",
124
"customizations": {
135
"vscode": {
146
"extensions": [
15-
"vscjava.vscode-java-pack",
16-
"vscjava.vscode-gradle",
7+
"redhat.java",
178
"ms-vscode.vscode-json"
189
]
1910
}
20-
},
21-
"mounts": [
22-
"source=gradle-cache,target=/home/vscode/.gradle,type=volume"
23-
],
24-
"remoteUser": "vscode",
25-
"postCreateCommand": "sudo chown -R vscode:vscode /home/vscode/.gradle"
11+
}
2612
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
name: Build Devcontainer Image
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
workflow_dispatch:
8+
inputs:
9+
force_rebuild:
10+
description: 'Force rebuild without cache'
11+
type: boolean
12+
default: false
13+
14+
jobs:
15+
build-and-push-devcontainer:
16+
runs-on: ubuntu-latest
17+
permissions:
18+
contents: read
19+
packages: write
20+
21+
steps:
22+
- name: Checkout repository
23+
uses: actions/checkout@v4
24+
25+
- name: Log in to Container Registry
26+
uses: docker/login-action@v3
27+
with:
28+
registry: ghcr.io
29+
username: ${{ github.actor }}
30+
password: ${{ secrets.GITHUB_TOKEN }}
31+
32+
- name: Extract metadata
33+
id: meta
34+
uses: docker/metadata-action@v5
35+
with:
36+
images: ghcr.io/${{ github.repository }}/devcontainer
37+
tags: |
38+
type=ref,event=branch
39+
type=sha
40+
type=raw,value=latest,enable={{is_default_branch}}
41+
42+
- name: Set up Docker Buildx
43+
uses: docker/setup-buildx-action@v3
44+
45+
- name: Build and push Docker image
46+
uses: docker/build-push-action@v5
47+
with:
48+
context: .
49+
file: .devcontainer/Dockerfile
50+
push: true
51+
tags: ${{ steps.meta.outputs.tags }}
52+
labels: ${{ steps.meta.outputs.labels }}
53+
platforms: linux/amd64
54+
cache-from: ${{ github.event.inputs.force_rebuild != 'true' && 'type=gha' || '' }}
55+
cache-to: type=gha,mode=max

smoke-tests/apps/gRPC/build.gradle.kts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@ plugins {
55
id("com.google.protobuf") version "0.8.19"
66
}
77

8-
val grpcVersion = "1.16.1"
9-
val nettyVersion = "4.1.30.Final"
8+
val grpcVersion = "1.26.0" // first version with support for arm64
9+
val nettyVersion = "4.1.42.Final"
1010

1111
protobuf {
1212
protoc {
1313
// Download compiler rather than using locally installed version:
14-
artifact = "com.google.protobuf:protoc:3.3.0"
14+
artifact = "com.google.protobuf:protoc:3.5.0" // first version with support for arm64
1515
}
1616
plugins {
1717
id("grpc") {

0 commit comments

Comments
 (0)