forked from Sage-Bionetworks/sage-monorepo
-
Notifications
You must be signed in to change notification settings - Fork 0
87 lines (74 loc) · 2.86 KB
/
build-devcontainer-image.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
name: Build Dev Container Image
on:
push:
branches:
- 'main'
paths:
- '.github/workflows/build-devcontainer-image.yml'
- 'tools/devcontainers/sage/**/devcontainer.json'
- 'tools/devcontainers/sage/**/Dockerfile'
pull_request:
paths:
- '.github/workflows/build-devcontainer-image.yml'
- 'tools/devcontainers/sage/**/devcontainer.json'
- 'tools/devcontainers/sage/**/Dockerfile'
env:
IMAGE_REPOSITORY: ghcr.io/sage-bionetworks/sage-devcontainer
DEFAULT_BRANCH: main
jobs:
devcontainer:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Lint Dockerfile
uses: docker://hadolint/hadolint:latest
with:
entrypoint: hadolint
args: tools/devcontainers/sage/.devcontainer/Dockerfile
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
- name: Cache Docker layers
uses: actions/cache@v3
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-single-buildx-${{ github.sha }}
restore-keys: |
${{ runner.os }}-single-buildx
- name: Set buildx as the default builder
run: docker buildx install
- name: Prepare the image build
id: prep
run: |
DEVCONTAINER_VERSION="${GITHUB_SHA::7}"
IMAGE_NAME="${{ env.IMAGE_REPOSITORY }}"
echo "image_name=${IMAGE_NAME}" >> $GITHUB_OUTPUT
echo "devcontainer_version=${DEVCONTAINER_VERSION}" >> $GITHUB_OUTPUT
- name: Build the image
run: |
WORKSPACE_FOLDER="tools/devcontainers/sage"
IMAGE_NAME=${{ steps.prep.outputs.image_name }}
IMAGE_TAG=${{ steps.prep.outputs.devcontainer_version }}
# [Optional] Enable buildkit, set output to plain text for logging
export DOCKER_BUILDKIT=1
export BUILDKIT_PROGRESS=plain
# Export the devcontainer version, which will be set inside the image. See
# devcontainer.json used to build the image.
export DEVCONTAINER_VERSION=${{ steps.prep.outputs.devcontainer_version }}
# Build the image
npm install -g @devcontainers/[email protected]
devcontainer build \
--image-name "${IMAGE_NAME}:${IMAGE_TAG}" \
--workspace-folder "${WORKSPACE_FOLDER}"
- name: Login to GitHub Container Registry
if: ${{ github.event_name != 'pull_request' }}
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Push the image to GitHub Container Registry
if: ${{ github.event_name != 'pull_request' }}
run: |
IMAGE_NAME=${{ steps.prep.outputs.image_name }}
IMAGE_TAG=${{ steps.prep.outputs.devcontainer_version }}
docker push "${IMAGE_NAME}:${IMAGE_TAG}"