Skip to content

Commit 83033f4

Browse files
authored
Merge pull request #12 from asw101/main
Add multiple dev containers, actions workflow to publish container image, tweak install.sh
2 parents 27dd3ed + bab8479 commit 83033f4

File tree

6 files changed

+120
-9
lines changed

6 files changed

+120
-9
lines changed

.devcontainer/devcontainer.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"image": "ghcr.io/asw101/rust-wasi-hello-devcontainer:latest",
3+
"features": {
4+
//"ghcr.io/devcontainers/features/rust:1": {},
5+
"ghcr.io/devcontainers/features/azure-cli:1": {}
6+
},
7+
"customizations": {
8+
"vscode": {
9+
"extensions": [
10+
"rust-lang.rust-analyzer"
11+
]
12+
}
13+
}
14+
}

.devcontainer/docker/Dockerfile

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
ARG TAG="latest"
2+
FROM mcr.microsoft.com/devcontainers/rust:${TAG}
3+
4+
USER vscode
5+
6+
COPY ./scripts /tmp/scripts/
7+
RUN bash /tmp/scripts/install.sh
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"build": {
3+
"dockerfile": "Dockerfile",
4+
"context": "../../"
5+
},
6+
//"image": "mcr.microsoft.com/devcontainers/universal:2",
7+
"features": {
8+
"ghcr.io/devcontainers/features/rust:1": {},
9+
"ghcr.io/devcontainers/features/azure-cli:1": {}
10+
},
11+
"customizations": {
12+
"vscode": {
13+
"extensions": [
14+
"rust-lang.rust-analyzer"
15+
]
16+
}
17+
}
18+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"image": "mcr.microsoft.com/devcontainers/universal:2",
3+
"features": {
4+
"ghcr.io/devcontainers/features/rust:1": {},
5+
"ghcr.io/devcontainers/features/azure-cli:1": {}
6+
},
7+
"postCreateCommand": "bash scripts/install.sh",
8+
"customizations": {
9+
"vscode": {
10+
"extensions": [
11+
"rust-lang.rust-analyzer"
12+
]
13+
}
14+
}
15+
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
#
2+
name: Publish devcontainer docker image
3+
4+
# Configures this workflow to run every time a change is pushed to the branch called `release`.
5+
on:
6+
push:
7+
branches: ['latest']
8+
workflow_dispatch:
9+
10+
# Defines two custom environment variables for the workflow. These are used for the Container registry domain, and a name for the Docker image that this workflow builds.
11+
env:
12+
REGISTRY: ghcr.io
13+
IMAGE_NAME: ${{ github.repository }}-devcontainer
14+
15+
# There is a single job in this workflow. It's configured to run on the latest available version of Ubuntu.
16+
jobs:
17+
build-and-push-image:
18+
runs-on: ubuntu-latest
19+
# Sets the permissions granted to the `GITHUB_TOKEN` for the actions in this job.
20+
permissions:
21+
contents: read
22+
packages: write
23+
attestations: write
24+
id-token: write
25+
#
26+
steps:
27+
- name: Checkout repository
28+
uses: actions/checkout@v4
29+
# Uses the `docker/login-action` action to log in to the Container registry registry using the account and password that will publish the packages. Once published, the packages are scoped to the account defined here.
30+
- name: Log in to the Container registry
31+
uses: docker/login-action@65b78e6e13532edd9afa3aa52ac7964289d1a9c1
32+
with:
33+
registry: ${{ env.REGISTRY }}
34+
username: ${{ github.actor }}
35+
password: ${{ secrets.GITHUB_TOKEN }}
36+
# This step uses [docker/metadata-action](https://github.com/docker/metadata-action#about) to extract tags and labels that will be applied to the specified image. The `id` "meta" allows the output of this step to be referenced in a subsequent step. The `images` value provides the base name for the tags and labels.
37+
- name: Extract metadata (tags, labels) for Docker
38+
id: meta
39+
uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7
40+
with:
41+
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
42+
# This step uses the `docker/build-push-action` action to build the image, based on your repository's `Dockerfile`. If the build succeeds, it pushes the image to GitHub Packages.
43+
# It uses the `context` parameter to define the build's context as the set of files located in the specified path. For more information, see "[Usage](https://github.com/docker/build-push-action#usage)" in the README of the `docker/build-push-action` repository.
44+
# It uses the `tags` and `labels` parameters to tag and label the image with the output from the "meta" step.
45+
- name: Build and push Docker image
46+
id: push
47+
uses: docker/build-push-action@f2a1d5e99d037542a71f64918e516c093c6f3fc4
48+
with:
49+
context: .
50+
file: .devcontainer/docker/Dockerfile
51+
push: true
52+
tags: ${{ steps.meta.outputs.tags }}
53+
labels: ${{ steps.meta.outputs.labels }}
54+
55+
# This step generates an artifact attestation for the image, which is an unforgeable statement about where and how it was built. It increases supply chain security for people who consume the image. For more information, see "[AUTOTITLE](/actions/security-guides/using-artifact-attestations-to-establish-provenance-for-builds)."
56+
- name: Generate artifact attestation
57+
uses: actions/attest-build-provenance@v1
58+
with:
59+
subject-name: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME}}
60+
subject-digest: ${{ steps.push.outputs.digest }}
61+
push-to-registry: true
62+

scripts/install.sh

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,7 @@
1-
# setup dir
2-
mkdir -p tmp
3-
cd tmp
4-
5-
# install wkg
6-
git clone https://github.com/bytecodealliance/wasm-pkg-tools
7-
cd wasm-pkg-tools/crates/wkg
8-
cargo install --path .
9-
cd ../../../../
1+
curl https://wasmtime.dev/install.sh -sSf | bash
102

113
# install cargo-component
124
cargo install cargo-component --force --version 0.16.0
5+
6+
# install wkg
7+
cargo install wkg --force

0 commit comments

Comments
 (0)