Skip to content

Commit df6068e

Browse files
matifalijohnstcn
andauthored
ci: build and push image for main branch (#222)
Co-authored-by: Cian Johnston <[email protected]>
1 parent ca0d2d9 commit df6068e

File tree

2 files changed

+49
-3
lines changed

2 files changed

+49
-3
lines changed

.github/workflows/ci.yaml

+48-1
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,12 @@ permissions:
1515
contents: read
1616
deployments: none
1717
issues: none
18-
packages: none
1918
pull-requests: none
2019
repository-projects: none
2120
security-events: none
2221
statuses: none
22+
# Necessary to push docker images to ghcr.io.
23+
packages: write
2324

2425
# Cancel in-progress runs for pull requests when developers push
2526
# additional changes
@@ -67,3 +68,49 @@ jobs:
6768

6869
- name: Check format
6970
run: ./scripts/check_fmt.sh
71+
build:
72+
runs-on: ubuntu-latest
73+
steps:
74+
- name: Checkout
75+
uses: actions/checkout@v4
76+
with:
77+
# Needed to get older tags
78+
fetch-depth: 0
79+
80+
- uses: actions/setup-go@v5
81+
with:
82+
go-version: "~1.22"
83+
84+
- name: Login to GitHub Container Registry
85+
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
86+
uses: docker/login-action@v2
87+
with:
88+
registry: ghcr.io
89+
username: ${{ github.actor }}
90+
password: ${{ secrets.GITHUB_TOKEN }}
91+
92+
# do not push images for pull requests
93+
- name: Build
94+
if: github.event_name == 'pull_request'
95+
run: |
96+
VERSION=$(./scripts/version.sh)-dev-$(git rev-parse --short HEAD)
97+
BASE=ghcr.io/coder/envbuilder-preview
98+
99+
./scripts/build.sh \
100+
--arch=amd64 \
101+
--base=$BASE \
102+
--tag=$VERSION
103+
104+
- name: Build and Push
105+
if: github.ref == 'refs/heads/main'
106+
run: |
107+
VERSION=$(./scripts/version.sh)-dev-$(git rev-parse --short HEAD)
108+
BASE=ghcr.io/coder/envbuilder-preview
109+
110+
./scripts/build.sh \
111+
--arch=amd64 \
112+
--arch=arm64 \
113+
--arch=arm \
114+
--base=$BASE \
115+
--tag=$VERSION \
116+
--push

scripts/build.sh

+1-2
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ if [ -z "$BUILDER_EXISTS" ]; then
4141
docker buildx create --use --platform=linux/arm64,linux/amd64,linux/arm/v7 --name $BUILDER_NAME
4242
else
4343
echo "Builder $BUILDER_NAME already exists. Using it."
44-
docker buildx use $BUILDER_NAME
4544
fi
4645

4746
# Ensure the builder is bootstrapped and ready to use
@@ -63,7 +62,7 @@ else
6362
args+=( --load )
6463
fi
6564

66-
docker buildx build "${args[@]}" -t $base:$tag -t $base:latest -f Dockerfile .
65+
docker buildx build --builder $BUILDER_NAME "${args[@]}" -t $base:$tag -t $base:latest -f Dockerfile .
6766

6867
# Check if archs contains the current. If so, then output a message!
6968
if [[ -z "${CI:-}" ]] && [[ " ${archs[@]} " =~ " ${current} " ]]; then

0 commit comments

Comments
 (0)