Skip to content

Commit 845fe36

Browse files
committed
ui: Implement build & push Docker image.
1 parent e753338 commit 845fe36

File tree

8 files changed

+117
-13
lines changed

8 files changed

+117
-13
lines changed

.github/workflows/main.yml

Lines changed: 70 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ jobs:
2121
name: Install Nix
2222
uses: cachix/install-nix-action@v27
2323
with:
24-
nix_path: nixpkgs=channel:nixos-24.05
24+
nix_path: nixpkgs=channel:nixos-24.11
2525
-
2626
name: Cargo cache
2727
uses: actions/cache@v4
@@ -31,8 +31,75 @@ jobs:
3131
~/.cargo/registry/index/
3232
~/.cargo/registry/cache/
3333
~/.cargo/git/db/
34-
test-runner/target/
34+
interface/target/
3535
key: ${{ runner.os }}-cargo-test-${{ hashFiles('**/Cargo.lock') }}
3636
-
3737
name: Run tests
38-
run: nix-shell --command "make nix-test"
38+
run: nix-shell --command "make test"
39+
40+
dist:
41+
needs: tests
42+
runs-on: ubuntu-latest
43+
if: startsWith(github.ref, 'refs/tags/v')
44+
steps:
45+
-
46+
name: Checkout
47+
uses: actions/checkout@v4
48+
-
49+
name: Install Nix
50+
uses: cachix/install-nix-action@v27
51+
with:
52+
nix_path: nixpkgs=channel:nixos-24.11
53+
-
54+
name: Cargo cache
55+
uses: actions/cache@v4
56+
with:
57+
path: |
58+
~/.cargo/bin/
59+
~/.cargo/registry/index/
60+
~/.cargo/registry/cache/
61+
~/.cargo/git/db/
62+
interface/target/
63+
key: ${{ runner.os }}-cargo-test-${{ hashFiles('**/Cargo.lock') }}
64+
-
65+
name: Install dev dependencies
66+
run: nix-shell --command "make dev-dependencies"
67+
-
68+
name: Build
69+
run: nix-shell --command "make build"
70+
-
71+
name: Docker meta
72+
id: meta
73+
uses: docker/metadata-action@v3
74+
with:
75+
images: |
76+
chirpstack/${{ github.event.repository.name }}
77+
tags: |
78+
type=semver,pattern={{version}}
79+
type=semver,pattern={{major}}
80+
type=semver,pattern={{major}}.{{minor}}
81+
-
82+
name: Set up QEMU
83+
uses: docker/setup-qemu-action@v1
84+
-
85+
name: Set up Docker Buildx
86+
uses: docker/setup-buildx-action@v1
87+
-
88+
name: Login to DockerHub
89+
uses: docker/login-action@v1
90+
with:
91+
username: ${{ secrets.DOCKERHUB_USERNAME }}
92+
password: ${{ secrets.DOCKERHUB_TOKEN }}
93+
-
94+
name: Build and push
95+
id: docker_build
96+
uses: docker/build-push-action@v2
97+
with:
98+
context: .
99+
push: ${{ startsWith(github.ref, 'refs/tags/v') }}
100+
platforms: linux/arm64
101+
tags: ${{ steps.meta.outputs.tags }}
102+
labels: ${{ steps.meta.outputs.labels }}
103+
-
104+
name: Image digest
105+
run: echo ${{ steps.docker_build.outputs.digest }}

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# hiddden files
22
.*
33
!.gitignore
4+
!.github
45

56
# builds
67
/interface/target

Dockerfile

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,23 @@
1-
FROM nixos/nix
1+
# Copy binary stage
2+
FROM --platform=$BUILDPLATFORM alpine:3.22.1 as binary
23

3-
ENV PROJECT_PATH=/lorawan-device-profiles
4-
WORKDIR $PROJECT_PATH
4+
ARG TARGETPLATFORM
55

6-
ENTRYPOINT ["nix-shell"]
6+
COPY target/x86_64-unknown-linux-musl/release/chirpstack-device-profiles-interface /usr/bin/chirpstack-device-profiles-interface-x86_64
7+
8+
RUN case "$TARGETPLATFORM" in \
9+
"linux/amd64") \
10+
cp /usr/bin/chirpstack-device-profiles-interface-x86_64 /usr/bin/chirpstack-device-profiles-interface; \
11+
;; \
12+
esac;
13+
14+
# Final stage
15+
FROM alpine:3.22.1
16+
17+
RUN apk --no-cache add \
18+
ca-certificates
19+
20+
COPY --from=binary /usr/bin/chirpstack-device-profiles-interface /usr/bin/chirpstack-device-profiles-interface
21+
USER nobody:nogroup
22+
ENTRYPOINT ["/usr/bin/chirpstack-device-profiles-interface"]
723

Makefile

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
.PHONY: test nix-start nix-test
22

3-
test:
4-
docker compose run --rm lorawan-device-profiles --run 'make nix-test'
3+
build:
4+
cd interface && make api ui release-amd64
55

6-
nix-start:
7-
cd interface && make ui && cargo run
6+
dev-shell:
7+
nix-shell
88

9-
nix-test:
9+
test:
1010
cd interface && make api ui
1111
cd interface && cargo run run-tests
12+
13+
dev-dependencies:
14+
cargo install cross --git https://github.com/cross-rs/cross --rev c7dee4d008475ce1c140773cbcd6078f4b86c2aa --locked

interface/Cross.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[build]
2+
default-target = "x86_64-unknown-linux-musl"
3+
4+
[target.x86_64-unknown-linux-musl]
5+
dockerfile = "cross/Dockerfile.x86_64-unknown-linux-musl"

interface/Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
PROTOC_PATH := ./ui/node_modules/grpc-tools/bin/protoc
44
PROTOC_ARGS := -I=./api --js_out=import_style=commonjs:./api/grpc-web --grpc-web_out=import_style=commonjs+dts,mode=grpcwebtext:./api/grpc-web/
55

6+
release-amd64:
7+
cross build --target x86_64-unknown-linux-musl --release
8+
69
api:
710
cd ui && yarn install
811

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
FROM ghcr.io/cross-rs/x86_64-unknown-linux-musl:main
2+
3+
RUN apt-get update && \
4+
apt-get --assume-yes install \
5+
protobuf-compiler \
6+
libprotobuf-dev
7+

shell.nix

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,7 @@ pkgs.mkShell {
88
pkgs.yarn
99
pkgs.protoc-gen-grpc-web
1010
];
11+
shellHook = ''
12+
export PATH=$PATH:~/.cargo/bin
13+
'';
1114
}
12-

0 commit comments

Comments
 (0)