Skip to content

Commit

Permalink
Merge pull request #2 from gla-rad/grad
Browse files Browse the repository at this point in the history
Adding the docker functionality from the grad branch
  • Loading branch information
nvasta authored Jun 7, 2024
2 parents 10a0502 + 924227d commit eba999d
Show file tree
Hide file tree
Showing 4 changed files with 176 additions and 0 deletions.
17 changes: 17 additions & 0 deletions .github/workflows/edgerouter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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' }}
17 changes: 17 additions & 0 deletions .github/workflows/router.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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' }}
76 changes: 76 additions & 0 deletions docker/Dockerfile.edgerouter
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
# Build like this:
# docker build -t <version> -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" \
# <image-id>
#
# 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"]
66 changes: 66 additions & 0 deletions docker/Dockerfile.router
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# Build like this:
# docker build -t <version> -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" \
# <image-id>
#
# 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"]

0 comments on commit eba999d

Please sign in to comment.