From a52d651ba9edb1071ac1c4f7dcb7da290eddd00e Mon Sep 17 00:00:00 2001 From: Sean Shahkarami Date: Fri, 22 Sep 2023 18:29:36 -0500 Subject: [PATCH 1/4] reworked dockerfile and added .dockerignore --- .dockerignore | 7 ++++++ Dockerfile | 60 +++++++++++++-------------------------------------- 2 files changed, 22 insertions(+), 45 deletions(-) create mode 100644 .dockerignore diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..c726a5d --- /dev/null +++ b/.dockerignore @@ -0,0 +1,7 @@ +* +!go.mod +!go.sum +!**/*.go +!requirements.txt +!**/*.py +!Makefile \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 9ceb13a..dfd1439 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,52 +1,22 @@ -FROM waggle/plugin-base:1.1.1-base as base +FROM golang:1.20 as builder +WORKDIR /build -RUN apt-get update \ - && apt-get install -y \ - build-essential \ - pkg-config \ - # build-base \ - wget \ - # libzmq3-dev \ -# zeromq-dev \ - # libczmq-dev \ -# czmq-dev \ - && rm -rf /var/lib/apt/lists/* -# libczmq-dev +COPY go.mod go.sum ./ +RUN go mod download -ARG TARGETARCH -WORKDIR /tmp -RUN wget https://golang.org/dl/go1.20.3.linux-${TARGETARCH}.tar.gz \ - && rm -rf /usr/local/go && tar -C /usr/local -xzf go1.20.3.linux-${TARGETARCH}.tar.gz \ - && echo "PATH=\$PATH:/usr/local/go/bin" | tee -a $HOME/.bashrc \ - && rm go1.20.3.linux-${TARGETARCH}.tar.gz - -FROM base as builder -WORKDIR $GOPATH/src/github.com/waggle-sensor/edge-scheduler -ARG TARGETARCH -COPY . . ARG VERSION ENV VERSION=${VERSION} -RUN export PATH=$PATH:/usr/local/go/bin:/usr/bin/pkg-config \ - && make scheduler-${TARGETARCH} cli-linux-${TARGETARCH} \ - && mkdir -p /app \ - && cp ./out/* /app/ \ - && cp pkg/knowledgebase/kb.py /app/ \ - && cp -r pkg/knowledgebase/util /app/ - -FROM base -ARG TARGETARCH -COPY requirements.txt /app/ -RUN pip3 install -r /app/requirements.txt +COPY . . +RUN go build -ldflags "-X main.Version=${VERSION}" -o ./ ./... -COPY --from=builder /app/ /app/ +FROM python:3.11 +WORKDIR /app -RUN chmod +x /app/cloudscheduler-${TARGETARCH} \ - && ln -s /app/cloudscheduler-${TARGETARCH} /usr/bin/cloudscheduler \ - && chmod +x /app/nodescheduler-${TARGETARCH} \ - && ln -s /app/nodescheduler-${TARGETARCH} /usr/bin/nodescheduler \ - && chmod +x /app/pluginctl-linux-${TARGETARCH} \ - && ln -s /app/pluginctl-linux-${TARGETARCH} /usr/bin/pluginctl \ - && chmod +x /app/runplugin-linux-${TARGETARCH} \ - && ln -s /app/runplugin-linux-${TARGETARCH} /usr/bin/runplugin +COPY requirements.txt . +RUN pip3 install -r requirements.txt -WORKDIR /app +COPY --from=builder /build/cloudscheduler /usr/bin/cloudscheduler +COPY --from=builder /build/nodescheduler /usr/bin/nodescheduler +COPY --from=builder /build/pluginctl /usr/bin/pluginctl +COPY --from=builder /build/runplugin /usr/bin/runplugin +COPY pkg/knowledgebase/kb.py pkg/knowledgebase/util /app/ From 5a09f262c9eba63a49a09911ae96a49103561a17 Mon Sep 17 00:00:00 2001 From: Sean Shahkarami Date: Sat, 23 Sep 2023 18:07:24 -0500 Subject: [PATCH 2/4] copy python script before go executables --- .dockerignore | 1 - Dockerfile | 5 +++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.dockerignore b/.dockerignore index c726a5d..0a42ee0 100644 --- a/.dockerignore +++ b/.dockerignore @@ -4,4 +4,3 @@ !**/*.go !requirements.txt !**/*.py -!Makefile \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index dfd1439..de8f43f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -4,9 +4,9 @@ WORKDIR /build COPY go.mod go.sum ./ RUN go mod download +COPY . . ARG VERSION ENV VERSION=${VERSION} -COPY . . RUN go build -ldflags "-X main.Version=${VERSION}" -o ./ ./... FROM python:3.11 @@ -15,8 +15,9 @@ WORKDIR /app COPY requirements.txt . RUN pip3 install -r requirements.txt +COPY pkg/knowledgebase/kb.py pkg/knowledgebase/util /app/ + COPY --from=builder /build/cloudscheduler /usr/bin/cloudscheduler COPY --from=builder /build/nodescheduler /usr/bin/nodescheduler COPY --from=builder /build/pluginctl /usr/bin/pluginctl COPY --from=builder /build/runplugin /usr/bin/runplugin -COPY pkg/knowledgebase/kb.py pkg/knowledgebase/util /app/ From c114042c428e5be158b6ca4d0fd4183af0806039 Mon Sep 17 00:00:00 2001 From: Sean Shahkarami Date: Sat, 23 Sep 2023 18:20:45 -0500 Subject: [PATCH 3/4] combined copy from builder steps --- Dockerfile | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/Dockerfile b/Dockerfile index de8f43f..0912e02 100644 --- a/Dockerfile +++ b/Dockerfile @@ -17,7 +17,4 @@ RUN pip3 install -r requirements.txt COPY pkg/knowledgebase/kb.py pkg/knowledgebase/util /app/ -COPY --from=builder /build/cloudscheduler /usr/bin/cloudscheduler -COPY --from=builder /build/nodescheduler /usr/bin/nodescheduler -COPY --from=builder /build/pluginctl /usr/bin/pluginctl -COPY --from=builder /build/runplugin /usr/bin/runplugin +COPY --from=builder /build/cloudscheduler /build/nodescheduler /build/pluginctl /build/runplugin /usr/bin/ From 492e0d918d082ee0c39e6831775425632aaacbf2 Mon Sep 17 00:00:00 2001 From: Sean Shahkarami Date: Sat, 23 Sep 2023 18:50:10 -0500 Subject: [PATCH 4/4] removed unused docker push in cicd workflow --- .github/workflows/cicd.yaml | 43 ++++--------------------------------- 1 file changed, 4 insertions(+), 39 deletions(-) diff --git a/.github/workflows/cicd.yaml b/.github/workflows/cicd.yaml index ed82ed0..76c5269 100644 --- a/.github/workflows/cicd.yaml +++ b/.github/workflows/cicd.yaml @@ -5,13 +5,12 @@ jobs: name: CI/CD runs-on: ubuntu-20.04 steps: - - uses: actions/checkout@v3 - - name: Setup Go - uses: actions/setup-go@v4 + - uses: actions/checkout@v4 + - uses: actions/setup-go@v4 with: go-version-file: "go.mod" - - name: Run tests - run: go test -v ./... + - run: go build -v ./... + - run: go test -v ./... - name: Get release version if: startsWith(github.ref, 'refs/tags/') run: echo "RELEASE_VERSION=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV @@ -44,37 +43,3 @@ jobs: ./out/sha256sum.txt env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - push_to_registry: - runs-on: ubuntu-latest - if: startsWith(github.ref, 'refs/tags/') - env: - REGISTRY: docker.io - IMAGE_NAME: waggle/scheduler - steps: - - name: Get release version - run: echo "RELEASE_VERSION=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV - - - name: Checkout repo - uses: actions/checkout@v2 - - - name: Set up QEMU for multi-arch builds - uses: docker/setup-qemu-action@v1 - - - name: Set up Docker buildx for multi-arch builds - uses: docker/setup-buildx-action@v1 - - - name: Login to Github Package Registry - uses: docker/login-action@v1 - with: - registry: ${{ env.REGISTRY }} - username: ${{ secrets.DOCKERHUB_USERNAME }} - password: ${{ secrets.DOCKERHUB_TOKEN }} - - - name: Build and push - uses: docker/build-push-action@v2 - with: - build-args: VERSION=${{ env.RELEASE_VERSION }} - context: . - platforms: linux/amd64,linux/arm64 - push: true - tags: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.RELEASE_VERSION }}