Skip to content

Commit

Permalink
Merge pull request #30 from docker/further-containerize
Browse files Browse the repository at this point in the history
Further containerize
  • Loading branch information
chris-crone authored Aug 18, 2020
2 parents 3e73705 + bb417d4 commit 32dbb3a
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 53 deletions.
41 changes: 4 additions & 37 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,46 +8,13 @@ jobs:
- name: Begin CI...
uses: actions/checkout@v2

- name: Use Node 12
uses: actions/setup-node@v1
with:
node-version: 12.x

- name: Use cached node_modules
uses: actions/cache@v1
with:
path: node_modules
key: nodeModules-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
nodeModules-
- name: Link docker command line
run: ln -s $(which docker) /tmp/com.docker.cli

- name: Add cli to path
run: echo "::add-path::/tmp"

- name: Install dependencies
run: yarn install --frozen-lockfile
env:
CI: true

- name: Lint
run: yarn lint
env:
CI: true

- name: Download CLI
env:
DOCKER_GITHUB_TOKEN: ${{ secrets.DOCKER_GITHUB_TOKEN }}
run: yarn download-cli
run: make lint

- name: Test
run: yarn test --ci --coverage --maxWorkers=2
run: make test
env:
CI: true
DOCKER_GITHUB_TOKEN: ${{ secrets.DOCKER_GITHUB_TOKEN }}

- name: Build
run: yarn build
env:
CI: true
run: make build
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
*.log
node_modules
src/*.js
src/*.map
src/*.d.ts
15 changes: 13 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
# syntax = docker/dockerfile:experimental
FROM node:12-buster-slim AS base
WORKDIR /src
ARG DOCKER_GITHUB_TOKEN
ENV DOCKER_GITHUB_TOKEN=${DOCKER_GITHUB_TOKEN}
COPY package.json .
COPY yarn.lock .

Expand All @@ -11,13 +9,26 @@ RUN --mount=type=cache,target=/usr/local/share/.cache/yarn/v6 \

COPY . .

FROM base AS run-build
RUN yarn build

FROM scratch AS build
COPY --from=run-build /src/src /

FROM base AS lint
RUN yarn lint

FROM base AS test
CMD ["yarn", "test"]
VOLUME ["/var/run/docker.sock"]
COPY --from=docker /usr/local/bin/docker /usr/local/bin/com.docker.cli
ARG DOCKER_GITHUB_TOKEN
ENV DOCKER_GITHUB_TOKEN=${DOCKER_GITHUB_TOKEN}
RUN yarn download-cli

FROM base AS download-protos
ARG DOCKER_GITHUB_TOKEN
ENV DOCKER_GITHUB_TOKEN=${DOCKER_GITHUB_TOKEN}
RUN yarn download-protos
RUN ./protos.sh

Expand Down
29 changes: 20 additions & 9 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,20 +1,31 @@
ifeq (${DOCKER_GITHUB_TOKEN},)
@echo "DOCKER_GITHUB_TOKEN empty
@echo "Set with a GitHub token that has access to docker/compose-cli"
exit 1
endif
export DOCKER_BUILDKIT=1

IMG?=node-sdk-test

all: test
all: build

.PHONY: build
build:
@docker build --target build --output ./src .

.PHONY: test
test:
test: check-token
@docker build --target test --tag ${IMG} --build-arg DOCKER_GITHUB_TOKEN .
docker run --rm \
@docker run --rm \
-v /var/run/docker.sock:/var/run/docker.sock \
${IMG}
@docker rmi ${IMG}

.PHONY: lint
lint:
@docker build --target lint .

.PHONY: protos
protos:
protos: check-token
@docker build --target protos --build-arg DOCKER_GITHUB_TOKEN --output ./src .

.PHONY: check-token
check-token:
ifeq (${DOCKER_GITHUB_TOKEN},)
$(error "Set DOCKER_GITHUB_TOKEN with a GitHub token that has access to docker/compose-cli")
endif
11 changes: 6 additions & 5 deletions scripts/download-cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const download = async () => {

const latestRelease = latestReleases.data[0];

console.log(`Fount release ${latestRelease.name}`);
console.log(`Found release ${latestRelease.name}`);

const linuxAsset = latestRelease.assets.find(
(asset) => asset.name == 'docker-linux-amd64'
Expand All @@ -45,12 +45,13 @@ const download = async () => {

const response = await request(options);

const zipPath = linuxAsset.name;
const file = fs.createWriteStream(zipPath);
const binPath = linuxAsset.name;
const file = fs.createWriteStream(binPath);

file.write(Buffer.from(response.data));
file.end();
fs.chmodSync(path.resolve(zipPath), 755);
file.end(() => {
fs.chmodSync(path.resolve(binPath), 755);
});
};

(async function () {
Expand Down

0 comments on commit 32dbb3a

Please sign in to comment.