diff --git a/.github/workflows/publish-docker.yml b/.github/workflows/publish-docker.yml new file mode 100644 index 00000000..af33b388 --- /dev/null +++ b/.github/workflows/publish-docker.yml @@ -0,0 +1,54 @@ +name: Weaver Docker Generator +on: + push: + tags: [ '**' ] + branches: + - main + pull_request: + branches: + - main + paths: + - .github/workflows/publish-docker.yml + - 'src/**' + - 'creates/**' + +jobs: + tests: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Build the Docker image + run: docker build . -t weaver && docker run --rm weaver --help + + build-and-publish-docker: + runs-on: ubuntu-latest + needs: tests + steps: + - uses: actions/checkout@v4 + - name: Build the Docker image + run: docker build . -t weaver + - name: Push the Docker image + if: github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/') + run: | + echo "${{ secrets.DOCKER_PASSWORD }}" | docker login -u "${{ secrets.DOCKER_USERNAME }}" --password-stdin + function tag_and_push { + docker tag weaver "otel/weaver:${1}" && docker push "otel/weaver:${1}" + } + if [[ "${GITHUB_REF}" == "refs/heads/main" ]]; then + tag_and_push "latest" + elif [[ "${GITHUB_REF}" =~ refs/tags/v[0-9]+\.[0-9]+\.[0-9]+ ]]; then + TAG="${GITHUB_REF#"refs/tags/v"}" + tag_and_push "${TAG}" + else + tag_and_push "${GITHUB_REF#"refs/tags/"}" + fi + - name: Push the Dev Docker image + if: startsWith(github.ref, 'refs/heads/feature/') + run: | + echo "${{ secrets.DOCKER_PASSWORD }}" | docker login -u "${{ secrets.DOCKER_USERNAME }}" --password-stdin + function tag_and_push { + docker tag weaver "otel/weaver:${1}" && docker push "otel/weaver:${1}" + } + TAG="${GITHUB_REF#"refs/heads/"}" + TAG="${TAG/"/"/"-"}" + tag_and_push "${TAG}" \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..5e8d6c2f --- /dev/null +++ b/Dockerfile @@ -0,0 +1,21 @@ + +# The build image +FROM rust:1.76.0-alpine3.18 as weaver-build +RUN apk add musl-dev +WORKDIR /build +# list out directories to avoid pulling local cargo `target/` +COPY Cargo.toml /build/Cargo.toml +COPY Cargo.lock /build/Cargo.lock +COPY crates /build/crates +COPY data /build/data +COPY src /build/src +COPY templates /build/templates +COPY tests build/tests +RUN cargo build --release + +# The runtime image +FROM alpine:3.18.3 +LABEL maintainer="The OpenTelemetry Authors" +WORKDIR /weaver +COPY --from=weaver-build /build/target/release/weaver /weaver/weaver +ENTRYPOINT ["/weaver/weaver"] \ No newline at end of file