Skip to content

Commit

Permalink
start on both networks
Browse files Browse the repository at this point in the history
  • Loading branch information
coderbyheart committed Apr 3, 2024
1 parent 3ab275e commit 6abcbef
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 56 deletions.
58 changes: 7 additions & 51 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,37 +9,7 @@ env:
REPO_IMAGE_LATEST: ${{ vars.REGISTRY_LOGIN_SERVER }}/coap:latest

jobs:
image:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- name: Setup Go
uses: actions/setup-go@v5
with:
go-version: 1.22.1

- name: Build server
working-directory: server
run: go build

- name: Build image
run: |
docker build -t ${{ env.IMAGE_TAGGED }} .
- name: Log in to the infrastructure container registry
run: |
docker login -u ${{ vars.REGISTRY_USERNAME }} -p ${{ secrets.REGISTRY_PASSWORD }} ${{ vars.REGISTRY_LOGIN_SERVER }}
- name: Push image to the infrastructure container registry
run: |
docker tag ${{ env.IMAGE_TAGGED }} ${{ env.REPO_IMAGE_TAGGED }}
docker push ${{ env.REPO_IMAGE_TAGGED }}
tests:
needs: [image]

runs-on: ubuntu-latest

steps:
Expand All @@ -54,13 +24,13 @@ jobs:
working-directory: client
run: go build

- name: Log in to infrastructure container registry
run: |
docker login -u ${{ vars.REGISTRY_USERNAME }} -p ${{ secrets.REGISTRY_PASSWORD }} ${{ vars.REGISTRY_LOGIN_SERVER }}
- name: Build server
working-directory: server
run: go build

- name: Pull image from the infrastructure container registry
- name: Build image
run: |
docker pull ${{ env.REPO_IMAGE_TAGGED }}
docker build -t ${{ env.IMAGE_TAGGED }} .
- name: Run image
env:
Expand All @@ -87,23 +57,9 @@ jobs:
docker ps
docker container logs `docker ps | grep ${{ env.IMAGE_TAGGED }} | awk '{ print $1; }'`
publish:
if: github.ref == 'refs/heads/saga'

needs: [tests]

runs-on: ubuntu-latest

steps:
- name: Log in to infrastructure container registry
run: |
docker login -u ${{ vars.REGISTRY_USERNAME }} -p ${{ secrets.REGISTRY_PASSWORD }} ${{ vars.REGISTRY_LOGIN_SERVER }}
- name: Pull image from the infrastructure container registry
run: |
docker pull ${{ env.REPO_IMAGE_TAGGED }}
- name: Push image to the infrastructure container registry as latest
if: github.ref == 'refs/heads/saga'
run: |
docker login -u ${{ vars.REGISTRY_USERNAME }} -p ${{ secrets.REGISTRY_PASSWORD }} ${{ vars.REGISTRY_LOGIN_SERVER }}
docker tag ${{ env.REPO_IMAGE_TAGGED }} ${{ env.REPO_IMAGE_LATEST }}
docker push ${{ env.REPO_IMAGE_LATEST }}
7 changes: 4 additions & 3 deletions server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ func main() {
password := flag.String("password", "connect:anything",
"The password to use for the PSK in dTLS.")
dtls := flag.Bool("dTLS", false, "Start a dTLS server")
network := flag.String("network", "udp4",
"The network to use, `udp4` or `udp6`.")
flag.Parse()

storageConnectionString, ok := os.LookupEnv("STORAGE_CONNECTION_STRING")
Expand All @@ -48,12 +50,11 @@ func main() {
dTLSPort := 5689
udpAddr := fmt.Sprintf("%s:%d", *address, udpPort)
dtlsAddr := fmt.Sprintf("%s:%d", *address, dTLSPort)
network := "udp"

if *dtls {
log.Printf("dTLS UDP Server listening on: %s\n", dtlsAddr)
log.Printf("dTLS PSK: %s\n", *password)
log.Fatal(coap.ListenAndServeDTLS(network, dtlsAddr, &piondtls.Config{
log.Fatal(coap.ListenAndServeDTLS(*network, dtlsAddr, &piondtls.Config{
PSK: func(hint []byte) ([]byte, error) {
log.Printf("Client's hint: %s \n", hint)
return []byte(*password), nil
Expand All @@ -63,6 +64,6 @@ func main() {
}, r))
} else {
log.Printf("UDP Server listening on: %s\n", udpAddr)
log.Fatal(coap.ListenAndServe(network, udpAddr, r))
log.Fatal(coap.ListenAndServe(*network, udpAddr, r))
}
}
6 changes: 4 additions & 2 deletions server/start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ if [ -f $FILE ]; then
export STORAGE_CONNECTION_STRING=$(cat /run/secrets/STORAGE_CONNECTION_STRING)
fi

nohup /home/coap/coap-server -password "connect:anything" -dTLS &
nohup /home/coap/coap-server &
nohup /home/coap/coap-server -network udp4 -password "connect:anything" -dTLS &
nohup /home/coap/coap-server -network udp4 &
nohup /home/coap/coap-server -network udp6 -password "connect:anything" -dTLS &
nohup /home/coap/coap-server -network udp6 &

sleep 1

Expand Down

0 comments on commit 6abcbef

Please sign in to comment.