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

[chore] Build and publish application hosted in the repository for the Golang instrumentation E2E test #2097

Merged
merged 12 commits into from
Sep 22, 2023
Merged
61 changes: 61 additions & 0 deletions .github/workflows/publish-autoinstrumentation-e2e-images.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
name: "Publish instrumentation E2E images"

on:
push:
paths:
- 'tests/instrumentation-e2e-apps/**'
- '.github/workflows/publish-autoinstrumentation-e2e-images.yaml'
branches:
- main
pull_request:
paths:
- 'tests/instrumentation-e2e-apps/**'
- '.github/workflows/publish-autoinstrumentation-e2e-images.yaml'
workflow_dispatch:

concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
cancel-in-progress: true

jobs:
golang:
runs-on: ubuntu-20.04

steps:
- uses: actions/checkout@v3

- name: Docker meta
id: meta
uses: docker/metadata-action@v4
with:
images: ghcr.io/open-telemetry/opentelemetry-operator/golang-test
iblancasa marked this conversation as resolved.
Show resolved Hide resolved

- name: Set up QEMU
uses: docker/setup-qemu-action@v2

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2

- name: Cache Docker layers
uses: actions/cache@v3
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildx-

- name: Login to GitHub Package Registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build and push
uses: docker/build-push-action@v4
with:
context: tests/instrumentation-e2e-apps/golang
platforms: linux/arm64,linux/amd64,linux/s390x,linux/ppc64le
push: ${{ github.event_name == 'push' }}
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache
8 changes: 8 additions & 0 deletions tests/instrumentation-e2e-apps/golang/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
FROM golang:1.21.1 as builder
iblancasa marked this conversation as resolved.
Show resolved Hide resolved

COPY main.go .
RUN CGO_ENABLED=0 GOOS=linux GO111MODULE=on go build -o app main.go

FROM scratch
COPY --from=builder /go/app .
ENTRYPOINT ["./app"]
37 changes: 37 additions & 0 deletions tests/instrumentation-e2e-apps/golang/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// Copyright The OpenTelemetry Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package main

import (
"fmt"
"net/http"
"time"
)

func main() {
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
fmt.Println("Hi")
})

server := &http.Server{
Addr: ":8080",
ReadHeaderTimeout: 3 * time.Second,
Comment on lines +29 to +30
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make these constants for clarity?

}

err := server.ListenAndServe()
if err != nil {
panic(err)
}
}
Loading