Skip to content

Commit fe6f63a

Browse files
committed
refactor: building of docker images is more flexible
1 parent 3981912 commit fe6f63a

File tree

6 files changed

+133
-32
lines changed

6 files changed

+133
-32
lines changed

.github/workflows/scip-docker.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ on:
77
pull_request:
88
paths:
99
- '.github/workflows/**'
10-
- 'Dockerfile.autoindex'
10+
- 'Dockerfile'
1111

1212
jobs:
1313
build-image:
@@ -41,7 +41,7 @@ jobs:
4141
id: docker_build_autoindex
4242
uses: docker/build-push-action@v4
4343
with:
44-
file: Dockerfile.autoindex
44+
file: Dockerfile
4545
push: false
4646
tags: |
4747
sourcegraph/scip-python:test

.github/workflows/scip-release.yml

Lines changed: 85 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,33 +5,96 @@ on:
55
tags:
66
- v*
77

8+
concurrency:
9+
group: ${{ github.workflow }}-${{ github.ref }}
10+
cancel-in-progress: true
11+
812
jobs:
9-
release-image:
13+
publish:
1014
runs-on: ubuntu-latest
1115
steps:
12-
- uses: actions/checkout@v3
13-
- uses: docker/setup-buildx-action@v2
14-
- uses: actions/setup-node@v2
16+
- uses: actions/checkout@v4
17+
- uses: actions/setup-node@v4
1518
with:
16-
node-version: '16'
17-
registry-url: 'https://registry.npmjs.org'
18-
- run: npm install
19-
- run: cd ./packages/pyright-scip/ && npm install && npm run build
20-
- run: cd ./packages/pyright-scip/ && npm publish --access public
19+
cache: npm
20+
cache-dependency-path: '**/package-lock.json'
21+
node-version: 16
22+
registry-url: https://registry.npmjs.org
23+
24+
- run: npm ci
25+
- run: npm ci && npm run build
26+
working-directory: ./packages/pyright-scip/
27+
28+
- if: ${{ env.NODE_AUTH_TOKEN }}
29+
run: npm publish --access public
30+
working-directory: ./packages/pyright-scip/
2131
env:
22-
NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}
23-
- name: Login to DockerHub
24-
uses: docker/login-action@v2
32+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
33+
34+
docker:
35+
needs: publish
36+
strategy:
37+
fail-fast: false
38+
matrix:
39+
version_debian: [bookworm]
40+
version_python: ['3.10']
41+
version_node: ['16']
42+
43+
runs-on: ubuntu-latest
44+
permissions:
45+
contents: read
46+
packages: write
47+
48+
# Permissions used for artifact attestation.
49+
attestations: write
50+
id-token: write
51+
52+
steps:
53+
- uses: docker/login-action@v3
2554
with:
26-
username: ${{ secrets.DOCKER_USERNAME }}
27-
password: ${{ secrets.DOCKER_PASSWORD }}
28-
- name: Build and push
29-
id: docker_build_autoindex
30-
uses: docker/build-push-action@v4
55+
registry: ${{ vars.REGISTRY || 'docker.io' }}
56+
username: ${{ secrets.DOCKER_USERNAME || github.actor }}
57+
password: ${{ secrets.DOCKER_PASSWORD || secrets.GITHUB_TOKEN }}
58+
59+
# Use QEMU and Buildx so we can build for multiple platforms.
60+
- uses: docker/setup-qemu-action@v3
61+
- uses: docker/setup-buildx-action@v3
62+
63+
- name: Generate image tags
64+
id: meta
65+
uses: docker/metadata-action@v5
3166
with:
32-
file: Dockerfile.autoindex
33-
push: true
67+
images: ${{ vars.REGISTRY || 'docker.io' }}/${{ github.repository }}
68+
flavor: |
69+
latest=true
70+
# NOTE: The autoindex tag seems to be legacy and overlaps fully with latest, dropping it might be breaking change.
3471
tags: |
35-
sourcegraph/scip-python:autoindex
36-
sourcegraph/scip-python:latest
37-
sourcegraph/scip-python:${{ github.ref_name }}
72+
type=sha,
73+
type=schedule
74+
type=raw,value=autoindex
75+
type=semver,pattern={{version}}
76+
type=semver,pattern={{major}}.{{minor}}
77+
type=semver,pattern={{major}}
78+
79+
- name: Build and release image
80+
id: push
81+
uses: docker/build-push-action@v5
82+
with:
83+
cache-from: type=gha,scope=docker-${{ matrix.version_debian}}-${{ matrix.version_python}}-${{ matrix.version_node }}
84+
cache-to: type=gha,mode=max,scope=docker-${{ matrix.version_debian}}-${{ matrix.version_python}}-${{ matrix.version_node }}
85+
push: true
86+
tags: ${{ steps.meta.outputs.tags }}
87+
labels: ${{ steps.meta.outputs.labels }}
88+
platforms: linux/amd64,linux/arm64
89+
build-args: |-
90+
VERSION_DEBIAN=${{ matrix.version_debian }}
91+
VERSION_PYTHON=${{ matrix.version_python }}
92+
VERSION_NODE=${{ matrix.version_node }}
93+
VERSION_SCIP_PYTHON=${{ github.ref_name }}
94+
95+
- name: Generate artifact attestation
96+
uses: actions/attest-build-provenance@v1
97+
with:
98+
subject-name: ${{ vars.REGISTRY || 'docker.io' }}/${{ github.repository }}
99+
subject-digest: ${{ steps.push.outputs.digest }}
100+
push-to-registry: true

.vscode/settings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"editor.formatOnSave": true
99
},
1010
"editor.codeActionsOnSave": {
11-
"source.fixAll.eslint": true
11+
"source.fixAll.eslint": "explicit"
1212
},
1313
"typescript.tsdk": "node_modules/typescript/lib"
1414
}

Dockerfile

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
ARG VERSION_DEBIAN=bookworm
2+
3+
ARG VERSION_NODE=16
4+
ARG VERSION_PYTHON=3.10
5+
6+
ARG VERSION_SCIP_PYTHON=v0.6.0
7+
8+
FROM node:$VERSION_NODE-$VERSION_DEBIAN-slim as technology-node
9+
FROM python:$VERSION_PYTHON-slim-$VERSION_DEBIAN as technology-python
10+
11+
FROM buildpack-deps:$VERSION_DEBIAN as base
12+
13+
COPY --link --from=technology-node /usr/local /usr/local
14+
COPY --link --from=technology-python /usr/local /usr/local
15+
16+
# NOTE: ldconfig is needed for Python to understand where shared libraries are.
17+
RUN ldconfig \
18+
# We remove pre-installed yarn and enable corepack.
19+
&& rm -rf /usr/local/bin/yarn* \
20+
&& corepack enable \
21+
# NOTE: Smoke tests while having as little side effects as possible.
22+
&& node --version \
23+
&& yarn --version \
24+
&& npm --logs-max=0 --version \
25+
&& PYTHONDONTWRITEBYTECODE=1 python3 --version \
26+
&& pip --version
27+
28+
FROM base AS release
29+
30+
ARG VERSION_SCIP_PYTHON
31+
32+
# Install dependencies
33+
RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
34+
--mount=type=cache,target=/var/lib/apt,sharing=locked \
35+
apt-get update && apt-get install -y --no-install-recommends \
36+
git \
37+
bash \
38+
curl \
39+
&& rm -rf /var/lib/apt/lists/*
40+
41+
# Install packages
42+
RUN npm install -g @sourcegraph/scip-python@$VERSION_SCIP_PYTHON @sourcegraph/src
43+
44+
ENTRYPOINT [ "scip-python" ]

Dockerfile.autoindex

Lines changed: 0 additions & 6 deletions
This file was deleted.

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ $ # Install scip-python
1111
$ npm install -g @sourcegraph/scip-python
1212
```
1313

14-
scip-python requires Node v16 or newer. See the [Dockerfile](https://github.com/sourcegraph/scip-python/blob/scip/Dockerfile.autoindex) for an exact SHA that is tested.
14+
scip-python requires Node v16 or newer. See the [Dockerfile](https://github.com/sourcegraph/scip-python/blob/scip/Dockerfile) for an exact SHA that is tested.
1515

1616
scip-python uses `pip` to attempt to determine the versions and names of the packages available in your environment. If you do not use pip to install the packages, you can instead use the `--environment` flag to supply a list of packages to use as the environment. This will skip any calls out to pip to determine the state of your env. See [Environment](##-environment) for more information.
1717

0 commit comments

Comments
 (0)