From 39538652986975e800ade1f6d71a0722d005d7d9 Mon Sep 17 00:00:00 2001 From: Nikolaos Vastardis Date: Fri, 7 Jun 2024 14:44:28 +0100 Subject: [PATCH 1/4] Adding the dockerfile configuration --- .github/workflows/edgerouter.yml | 8 ++++ .github/workflows/router.yml | 8 ++++ docker/Dockerfile.edgerouter | 76 ++++++++++++++++++++++++++++++++ docker/Dockerfile.router | 66 +++++++++++++++++++++++++++ 4 files changed, 158 insertions(+) create mode 100644 docker/Dockerfile.edgerouter create mode 100644 docker/Dockerfile.router diff --git a/.github/workflows/edgerouter.yml b/.github/workflows/edgerouter.yml index f2cf806..6705098 100644 --- a/.github/workflows/edgerouter.yml +++ b/.github/workflows/edgerouter.yml @@ -23,3 +23,11 @@ jobs: - name: Build MMS Edge Router run: go build working-directory: ./edgerouter + + - name: Build and push Docker image + uses: docker/build-push-action@v3 + with: + context: docker + file: {context}/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..555813f 100644 --- a/.github/workflows/router.yml +++ b/.github/workflows/router.yml @@ -23,3 +23,11 @@ jobs: - name: Build MMS Router run: go build working-directory: ./router + + - name: Build and push Docker image + uses: docker/build-push-action@v3 + with: + context: docker + file: {context}/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"] From 2e2d54ce6a97e2b0bfcbc8484dedabe8f4c4bc86 Mon Sep 17 00:00:00 2001 From: Nikolaos Vastardis Date: Fri, 7 Jun 2024 14:51:37 +0100 Subject: [PATCH 2/4] Trying to fix the workflows --- .github/workflows/edgerouter.yml | 10 ++++++++++ .github/workflows/router.yml | 10 ++++++++++ 2 files changed, 20 insertions(+) diff --git a/.github/workflows/edgerouter.yml b/.github/workflows/edgerouter.yml index 6705098..ede3bbc 100644 --- a/.github/workflows/edgerouter.yml +++ b/.github/workflows/edgerouter.yml @@ -24,6 +24,16 @@ jobs: 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: diff --git a/.github/workflows/router.yml b/.github/workflows/router.yml index 555813f..18603e2 100644 --- a/.github/workflows/router.yml +++ b/.github/workflows/router.yml @@ -24,6 +24,16 @@ jobs: 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: From 3ee6f854d03d80b10a135e0bc6de20b186555119 Mon Sep 17 00:00:00 2001 From: Nikolaos Vastardis Date: Fri, 7 Jun 2024 14:54:16 +0100 Subject: [PATCH 3/4] Fixing the context variable name --- .github/workflows/edgerouter.yml | 2 +- .github/workflows/router.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/edgerouter.yml b/.github/workflows/edgerouter.yml index ede3bbc..94ed3c2 100644 --- a/.github/workflows/edgerouter.yml +++ b/.github/workflows/edgerouter.yml @@ -38,6 +38,6 @@ jobs: uses: docker/build-push-action@v3 with: context: docker - file: {context}/Dockerfile.edgerouter + file: ${context}/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 18603e2..ec9bced 100644 --- a/.github/workflows/router.yml +++ b/.github/workflows/router.yml @@ -38,6 +38,6 @@ jobs: uses: docker/build-push-action@v3 with: context: docker - file: {context}/Dockerfile.router + file: ${context}/Dockerfile.router tags: ghcr.io/gla-rad/mc-mms-edgerouter push: ${{ github.event_name == 'push' && github.ref == 'refs/heads/master' }} From 924227d91628450ff90918e2125d566d7df37115 Mon Sep 17 00:00:00 2001 From: Nikolaos Vastardis Date: Fri, 7 Jun 2024 14:55:47 +0100 Subject: [PATCH 4/4] Removing the workflow docker builder context variable --- .github/workflows/edgerouter.yml | 3 +-- .github/workflows/router.yml | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/.github/workflows/edgerouter.yml b/.github/workflows/edgerouter.yml index 94ed3c2..bdf6358 100644 --- a/.github/workflows/edgerouter.yml +++ b/.github/workflows/edgerouter.yml @@ -37,7 +37,6 @@ jobs: - name: Build and push Docker image uses: docker/build-push-action@v3 with: - context: docker - file: ${context}/Dockerfile.edgerouter + 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 ec9bced..fda5f80 100644 --- a/.github/workflows/router.yml +++ b/.github/workflows/router.yml @@ -37,7 +37,6 @@ jobs: - name: Build and push Docker image uses: docker/build-push-action@v3 with: - context: docker - file: ${context}/Dockerfile.router + file: docker/Dockerfile.router tags: ghcr.io/gla-rad/mc-mms-edgerouter push: ${{ github.event_name == 'push' && github.ref == 'refs/heads/master' }}