diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..0a42ee0 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,6 @@ +* +!go.mod +!go.sum +!**/*.go +!requirements.txt +!**/*.py 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 }} diff --git a/Dockerfile b/Dockerfile index 9ceb13a..0912e02 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,52 +1,20 @@ -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/ +RUN go build -ldflags "-X main.Version=${VERSION}" -o ./ ./... -FROM base -ARG TARGETARCH -COPY requirements.txt /app/ -RUN pip3 install -r /app/requirements.txt +FROM python:3.11 +WORKDIR /app -COPY --from=builder /app/ /app/ +COPY requirements.txt . +RUN pip3 install -r requirements.txt -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 pkg/knowledgebase/kb.py pkg/knowledgebase/util /app/ -WORKDIR /app +COPY --from=builder /build/cloudscheduler /build/nodescheduler /build/pluginctl /build/runplugin /usr/bin/