Skip to content

Commit 380440e

Browse files
committed
Better devcontainer
1 parent 5fef748 commit 380440e

File tree

4 files changed

+98
-13
lines changed

4 files changed

+98
-13
lines changed

.devcontainer/Dockerfile

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
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
5+
RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
6+
&& apt-get -y install --no-install-recommends \
7+
wget \
8+
ca-certificates \
9+
&& wget -q https://packages.microsoft.com/config/debian/11/packages-microsoft-prod.deb -O packages-microsoft-prod.deb \
10+
&& dpkg -i packages-microsoft-prod.deb \
11+
&& rm packages-microsoft-prod.deb \
12+
&& apt-get update \
13+
&& apt-get -y install --no-install-recommends \
14+
msopenjdk-17 \
15+
&& apt-get clean \
16+
&& rm -rf /var/lib/apt/lists/*
17+
18+
# Switch to vscode user for the build
19+
USER vscode
20+
21+
# Set working directory for build
22+
WORKDIR /tmp/build
23+
24+
# Copy all project files for the build
25+
COPY --chown=vscode:vscode . ./
26+
27+
# Pre-populate Gradle dependency and build caches by compiling all classes
28+
# Use --no-daemon to avoid leaving daemon processes running
29+
# Set JAVA_HOME dynamically based on the actual installation
30+
RUN export JAVA_HOME=$(find /usr/lib/jvm -name "msopenjdk-17-*" -type d | head -1) && \
31+
export PATH="$JAVA_HOME/bin:$PATH" && \
32+
./gradlew classes --no-daemon
33+
34+
# Clean up the build directory but preserve gradle cache
35+
RUN rm -rf /tmp/build
36+
37+
# Set default working directory for development
38+
WORKDIR /workspaces

.devcontainer/devcontainer.json

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
{
22
"name": "Application Insights Java Development Environment",
3-
"image": "mcr.microsoft.com/vscode/devcontainers/base:bullseye",
3+
"image": "ghcr.io/microsoft/applicationinsights-java/devcontainer:latest",
44
"features": {
5-
"ghcr.io/devcontainers/features/java:1": {
6-
"version": "17"
7-
},
85
"ghcr.io/devcontainers/features/docker-in-docker:2": {
96
"version": "latest"
107
}
@@ -17,10 +14,5 @@
1714
"ms-vscode.vscode-json"
1815
]
1916
}
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"
17+
}
2618
}
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,linux/arm64
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)