diff --git a/.github/workflows/edgerouter.yml b/.github/workflows/edgerouter.yml index f2cf806..bdf6358 100644 --- a/.github/workflows/edgerouter.yml +++ b/.github/workflows/edgerouter.yml @@ -23,3 +23,20 @@ jobs: - name: Build MMS Edge Router run: go build working-directory: ./edgerouter + + - name: Setup Docker Buildx + uses: docker/setup-buildx-action@v2 + + - name: Login to GHCR + uses: docker/login-action@v2 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Build and push Docker image + uses: docker/build-push-action@v3 + with: + file: docker/Dockerfile.edgerouter + tags: ghcr.io/gla-rad/mc-mms-edgerouter + push: ${{ github.event_name == 'push' && github.ref == 'refs/heads/master' }} diff --git a/.github/workflows/router.yml b/.github/workflows/router.yml index f2938c4..fda5f80 100644 --- a/.github/workflows/router.yml +++ b/.github/workflows/router.yml @@ -23,3 +23,20 @@ jobs: - name: Build MMS Router run: go build working-directory: ./router + + - name: Setup Docker Buildx + uses: docker/setup-buildx-action@v2 + + - name: Login to GHCR + uses: docker/login-action@v2 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Build and push Docker image + uses: docker/build-push-action@v3 + with: + file: docker/Dockerfile.router + tags: ghcr.io/gla-rad/mc-mms-edgerouter + push: ${{ github.event_name == 'push' && github.ref == 'refs/heads/master' }} diff --git a/docker/Dockerfile.edgerouter b/docker/Dockerfile.edgerouter new file mode 100644 index 0000000..a83e935 --- /dev/null +++ b/docker/Dockerfile.edgerouter @@ -0,0 +1,76 @@ +# Build like this: +# docker build -t -f Dockerfile .. +# e.g. +# docker build -t glarad/mc-mms-edgerouter:latest -f Dockerfile .. +# +# Run like this: +# sudo docker run -t -i --rm -p 8080:8080 -p 9000:9000 -v /path/to/config-directory/on/machine:/conf +# -e MRN="custom_mrn_value" \ +# -e RADDR="custom_raddr_value" \ +# -e PORT="8080" \ +# -e LIBP2P_PORT="9000" \ +# -e PRIVKEY="custom_privkey_value" \ +# -e CLIENT_CERT_PATH="custom_client_cert_path" \ +# -e CLIENT_CERT_KEY_PATH="custom_client_cert_key_path" \ +# -e CERT_PATH="custom_cert_path" \ +# -e CERT_KEY_PATH="custom_cert_key_path" \ +# -e CLIENT_CA="custom_client_ca" \ +# +# +# You can also push to docker-hub like: +# docker push glarad/mc-mms-edgerouter:tagname +# +# A customized conf file (application.properties) can be made available in the folder mounted to /conf. +# When using in non-local environment it is recommended to generate new trust and keystores and place them in +# the conf-folder and point to them in application.properties. +# + +# Start with the official Golang image +FROM golang:1.22 as builder + +# Set the Current Working Directory inside the container +WORKDIR /edgerouter + +# Copy the go.mod and go.sum files +COPY edgerouter/go.mod edgerouter/go.sum ./ + +# Copy the source code into the container +ADD edgerouter . + +# Copy the utility sources +COPY ./mmtp/ /mmtp/ +COPY ./utils/ /utils/ +COPY ./consumer/ /consumer/ + +# Build the Go app +RUN go build -o edgerouter . + +# Start a new stage from scratch +FROM alpine:latest + +# Set the Current Working Directory inside the container +WORKDIR /edgerouter + +RUN apk update && apk add -q ca-certificates + +# Copy the Pre-built binary file from the previous stage +COPY --from=builder /edgerouter/edgerouter . + +# Expose ports +EXPOSE 8080 +EXPOSE 9000 + +# Set default environment variables +ENV MRN="urn:mrn:mcp:device:idp1:org1:er" +ENV RADDR="ws://localhost:8080" +ENV PORT="8080" +ENV LIBP2P_PORT="9000" +ENV PRIVKEY="" +ENV CLIENT_CERT_PATH="" +ENV CLIENT_CERT_KEY_PATH="" +ENV CERT_PATH="" +ENV CERT_KEY_PATH="" +ENV CLIENT_CA="" + +# Command to run the executable with environment variables as input parameters +CMD ["sh", "-c", "./edgerouter --mrn $MRN --raddr $RADDR --port $PORT --libp2p-port $LIBP2P_PORT --privkey $PRIVKEY --cilent-cert $CLIENT_CERT_PATH --cilent-cert-key $CLIENT_CERT_KEY_PATH --cert-path $CERT_PATH --cert-key-path $CERT_KEY_PATH --client-ca $CLIENT_CA"] diff --git a/docker/Dockerfile.router b/docker/Dockerfile.router new file mode 100644 index 0000000..c3dbacc --- /dev/null +++ b/docker/Dockerfile.router @@ -0,0 +1,66 @@ +# Build like this: +# docker build -t -f Dockerfile .. +# e.g. +# docker build -t glarad/mc-mms-edgerouter:latest -f Dockerfile .. +# +# Run like this: +# sudo docker run -t -i --rm -p 8080:8080 -p 9000:9000 -v /path/to/config-directory/on/machine:/conf +# -e PORT="8080" \ +# -e LIBP2P_PORT="9000" \ +# -e PRIVKEY="custom_privkey_value" \ +# -e CERT_PATH="custom_cert_path" \ +# -e CERT_KEY_PATH="custom_cert_key_path" \ +# -e CLIENT_CA="custom_client_ca" \ +# +# +# You can also push to docker-hub like: +# docker push glarad/mc-mms-edgerouter:tagname +# +# A customized conf file (application.properties) can be made available in the folder mounted to /conf. +# When using in non-local environment it is recommended to generate new trust and keystores and place them in +# the conf-folder and point to them in application.properties. +# + +# Start with the official Golang image +FROM golang:1.22 as builder + +# Set the Current Working Directory inside the container +WORKDIR /router + +# Copy the go.mod and go.sum files +COPY router/go.mod router/go.sum ./ + +# Copy the source code into the container +ADD router . + +# Copy the utility sources +COPY ./mmtp/ ../mmtp/ +COPY ./utils/ ../utils/ +COPY ./consumer/ ../consumer/ + +# Build the Go app +RUN go build -o router . + +# Start a new stage from scratch +FROM alpine:latest + +# Set the Current Working Directory inside the container +WORKDIR /router + +# Copy the Pre-built binary file from the previous stage +COPY --from=builder /router/router . + +# Expose ports +EXPOSE 8080 +EXPOSE 9000 + +# Set default environment variables +ENV PORT="8080" +ENV LIBP2P_PORT="9000" +ENV PRIVKEY="default_privkey_value" +ENV CERT_PATH="default_cert_path" +ENV CERT_KEY_PATH="default_cert_key_path" +ENV CLIENT_CA="default_client_ca" + +# Command to run the executable with environment variables as input parameters +CMD ["sh", "-c", "./router --port $PORT --libp2p-port $LIBP2P_PORT --privkey $PRIVKEY --cert-path $CERT_PATH --cert-key-path $CERT_KEY_PATH --client-ca $CLIENT_CA"]