Skip to content

Commit c0a7853

Browse files
authored
chore: reduce build time by converting docker image to build with nix (#9099)
* Add Docker image * Try building the container in CI * Uncomment testing lines * Trim image step * Hit 'em with a Docker load * Oopsie! * Add a tag and push! * Fix image name 🤦 * Fix sudo * Fix target name * Build and push * Fix login to docker hub * Revert to Docker push * Fix PATH * Fix SHA * Fix ca certs * Fix ca certs * Fix coping files in * Fix docker init * Fix Docker group and init * Add comments to our Nix * Fix build stage * Add some more comments * Remove old dogfood image files * Tag and push with branch name * Fix tag passing * Fix tag passing * Remove old pull triggers * Convert gen to use Nix * Add protobuf to the flake * Add prettier to the dev shell * Swap to the faster Nix cache action * Add the correct yq * Fix gen * Add make to the flake * Update extensions
1 parent 5b165d5 commit c0a7853

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+221
-681
lines changed

.github/workflows/ci.yaml

+5-29
Original file line numberDiff line numberDiff line change
@@ -169,38 +169,14 @@ jobs:
169169
with:
170170
fetch-depth: 1
171171

172-
- name: Setup Node
173-
uses: ./.github/actions/setup-node
174-
175-
- name: Setup Go
176-
uses: ./.github/actions/setup-go
177-
178-
- name: Setup sqlc
179-
uses: ./.github/actions/setup-sqlc
180-
181-
- name: go install tools
182-
run: |
183-
go install google.golang.org/protobuf/cmd/protoc-gen-go@v1.30
184-
go install storj.io/drpc/cmd/protoc-gen-go-drpc@v0.0.33
185-
go install golang.org/x/tools/cmd/goimports@latest
186-
go install github.com/mikefarah/yq/v4@v4.30.6
187-
go install github.com/golang/mock/mockgen@v1.6.0
172+
- name: Install Nix
173+
uses: DeterminateSystems/nix-installer-action@v4
188174

189-
- name: Install Protoc
190-
run: |
191-
# protoc must be in lockstep with our dogfood Dockerfile or the
192-
# version in the comments will differ. This is also defined in
193-
# security.yaml
194-
set -x
195-
cd dogfood
196-
DOCKER_BUILDKIT=1 docker build . --target proto -t protoc
197-
protoc_path=/usr/local/bin/protoc
198-
docker run --rm --entrypoint cat protoc /tmp/bin/protoc > $protoc_path
199-
chmod +x $protoc_path
200-
protoc --version
175+
- name: Run the Magic Nix Cache
176+
uses: DeterminateSystems/magic-nix-cache-action@v2
201177

202178
- name: make gen
203-
run: "make --output-sync -j -B gen"
179+
run: "nix-shell --command 'make --output-sync -j -B gen'"
204180

205181
- name: Check for unstaged files
206182
run: ./scripts/check_unstaged.sh

.github/workflows/dogfood.yaml

+17-13
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,15 @@ on:
55
branches:
66
- main
77
paths:
8+
- "flake.nix"
9+
- "flake.lock"
810
- "dogfood/**"
911
- ".github/workflows/dogfood.yaml"
1012
# Uncomment these lines when testing with CI.
1113
# pull_request:
1214
# paths:
15+
# - "flake.nix"
16+
# - "flake.lock"
1317
# - "dogfood/**"
1418
# - ".github/workflows/dogfood.yaml"
1519
workflow_dispatch:
@@ -18,6 +22,9 @@ jobs:
1822
deploy_image:
1923
runs-on: buildjet-4vcpu-ubuntu-2204
2024
steps:
25+
- name: Checkout
26+
uses: actions/checkout@v3
27+
2128
- name: Get branch name
2229
id: branch-name
2330
uses: tj-actions/branch-names@v6.5
@@ -30,27 +37,24 @@ jobs:
3037
tag=${tag//\//--}
3138
echo "tag=${tag}" >> $GITHUB_OUTPUT
3239
33-
- name: Set up QEMU
34-
uses: docker/setup-qemu-action@v2
40+
- name: Install Nix
41+
uses: DeterminateSystems/nix-installer-action@v4
3542

36-
- name: Set up Docker Buildx
37-
uses: docker/setup-buildx-action@v2
43+
- name: Run the Magic Nix Cache
44+
uses: DeterminateSystems/magic-nix-cache-action@v2
45+
46+
- run: nix build .#devEnvImage && ./result | docker load
3847

3948
- name: Login to DockerHub
4049
uses: docker/login-action@v2
4150
with:
4251
username: ${{ secrets.DOCKERHUB_USERNAME }}
4352
password: ${{ secrets.DOCKERHUB_PASSWORD }}
4453

45-
- name: Build and push
46-
uses: docker/build-push-action@v4
47-
with:
48-
context: "{{defaultContext}}:dogfood"
49-
pull: true
50-
push: true
51-
tags: "codercom/oss-dogfood:${{ steps.docker-tag-name.outputs.tag }},codercom/oss-dogfood:latest"
52-
cache-from: type=registry,ref=codercom/oss-dogfood:latest
53-
cache-to: type=inline
54+
- name: Tag and Push
55+
run: |
56+
docker tag codercom/oss-dogfood:latest codercom/oss-dogfood:${{ steps.docker-tag-name.outputs.tag }}
57+
docker push codercom/oss-dogfood -a
5458
5559
deploy_template:
5660
needs: deploy_image

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -61,3 +61,6 @@ site/stats/
6161
./scaletest/terraform/.terraform.lock.hcl
6262
scaletest/terraform/secrets.tfvars
6363
.terraform.tfstate.*
64+
65+
# Nix
66+
result

.prettierignore

+3
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,9 @@ site/stats/
6464
./scaletest/terraform/.terraform.lock.hcl
6565
scaletest/terraform/secrets.tfvars
6666
.terraform.tfstate.*
67+
68+
# Nix
69+
result
6770
# .prettierignore.include:
6871
# Helm templates contain variables that are invalid YAML and can't be formatted
6972
# by Prettier.

0 commit comments

Comments
 (0)