diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml new file mode 100644 index 000000000..bdb266911 --- /dev/null +++ b/.github/workflows/build.yaml @@ -0,0 +1,63 @@ +name: Build registrator and containers +on: + workflow_dispatch: + # Trigger the workflow on push or pull request, + # but only for the main branch + push: + branches: + - master + pull_request: + branches: + - master +jobs: + prep: + outputs: + branch: ${{ steps.extract_branch.outputs.branch }} + runs-on: [self-hosted, linux] + steps: + - name: Extract branch name + shell: bash + run: echo "##[set-output name=branch;]$(echo ${GITHUB_REF#refs/heads/})" + id: extract_branch + build: + needs: prep + runs-on: [self-hosted, linux] + strategy: + matrix: + os: [linux, windows] + steps: + - uses: actions/checkout@v2 + - name: create registrator build container + run: | + docker build -t registrator-build:${{ matrix.os }} --build-arg OS=${{ matrix.os }} --build-arg ARCH=amd64 -f Dockerfile.build . + - name: run build container + run: | + mkdir ./output + docker run -v ./output:/out registrator-build:${{ matrix.os }} build -ldflags "-X main.Version=$(cat VERSION)" -o /out/registrator + - name: upload registrator binary + uses: actions/upload-artifact@v2 + with: + name: registrator-${{ matrix.os }} + path: output + retention-days: 1 + container: + needs: + - build + - prep + runs-on: [self-hosted, "${{ matrix.os }}"] + strategy: + matrix: + os: [linux, windows] + steps: + - name: download registrator binary + uses: actions/download-artifact@v2 + with: + name: registrator-${{ matrix.os }} + - name: create registator runtime container + env: + AWS_REGION: us-east-1 + run: | + docker build -t registrator:${{ matrix.os }}.${{ github.run_id }} -f Dockerfile.${{ matrix.os }} . + docker tag registrator:${{ matrix.os }}.${{ github.run_id }} ${{ secrets.AWS_WEB_ACCT }}.dkr.ecr.${{ env.AWS_REGION }}.amazonaws.com/registrator:${{ matrix.os }}.${{ needs.prep.outputs.branch }}.${{ github.run_id }} + docker login --username AWS -p $(aws ecr get-login-password --region ${{ env.AWS_REGION }} ) ${{ secrets.AWS_WEB_ACCT }}.dkr.ecr.${{ env.AWS_REGION }}.amazonaws.com + docker push ${{ secrets.AWS_WEB_ACCT }}.dkr.ecr.${{ env.AWS_REGION }}.amazonaws.com/registrator:${{ matrix.os }}.${{ needs.prep.outputs.branch }}.${{ github.run_id }} diff --git a/Dockerfile b/Dockerfile deleted file mode 100644 index f98a73bf5..000000000 --- a/Dockerfile +++ /dev/null @@ -1,17 +0,0 @@ -FROM alpine:3.8 -ENTRYPOINT ["/bin/run-registrator.sh"] - -RUN mkdir /logs -ENV GOPATH /go -COPY ./run-registrator.sh /bin -RUN chmod 755 /bin/run-registrator.sh -COPY . /go/src/github.com/gliderlabs/registrator -RUN apk --no-cache add -t build-deps build-base go git \ - && apk --no-cache add ca-certificates bash coreutils \ - && cd /go/src/github.com/gliderlabs/registrator \ - && export GOPATH=/go \ - && git config --global http.https://gopkg.in.followRedirects true \ - && go get \ - && go build -ldflags "-X main.Version=$(cat VERSION)" -o /bin/registrator \ - && rm -rf /go \ - && apk del --purge build-deps diff --git a/Dockerfile.build b/Dockerfile.build new file mode 100644 index 000000000..a8d42dcb8 --- /dev/null +++ b/Dockerfile.build @@ -0,0 +1,23 @@ +FROM alpine:3.8 + +ENV GOPATH /go +WORKDIR /go/src/github.com/gliderlabs/registrator +COPY . . + +RUN apk --no-cache add -t build-deps build-base go git \ + && apk --no-cache add ca-certificates bash coreutils \ + && cd /go/src/github.com/gliderlabs/registrator \ + && export GOPATH=/go \ + && git config --global http.https://gopkg.in.followRedirects true + +ARG OS="linux" +ARG ARCH="amd64" +ENV GOOS=${OS} +ENV GOARCH=${ARCH} + +RUN go get + +CMD ["go"] + + +#&& go build -ldflags "-X main.Version=$(cat VERSION)" -o /bin/registrator \ diff --git a/Dockerfile.linux b/Dockerfile.linux new file mode 100644 index 000000000..d52b6c2a8 --- /dev/null +++ b/Dockerfile.linux @@ -0,0 +1,7 @@ +FROM alpine:3.8 +ENTRYPOINT ["/bin/run-registrator.sh"] + +RUN mkdir /logs +COPY ./run-registrator.sh /bin +RUN chmod 755 /bin/run-registrator.sh +COPY ./output/registrator /bin/registrator diff --git a/Dockerfile.windows b/Dockerfile.windows new file mode 100644 index 000000000..93041e251 --- /dev/null +++ b/Dockerfile.windows @@ -0,0 +1,5 @@ +FROM mcr.microsoft.com/windows/servercore:ltsc2019 +SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"] +WORKDIR C:\\app +COPY ./output/registrator registrator.exe +ENTRYPOINT ["C:\\app\\registrator.exe"]