Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Dockerfile #110

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
*
!go.mod
!go.sum
!**/*.go
!requirements.txt
!**/*.py
43 changes: 4 additions & 39 deletions .github/workflows/cicd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 }}
54 changes: 11 additions & 43 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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/