Skip to content

Commit b27a929

Browse files
authored
Multiarch (#2)
* init * var for name
1 parent 5ec94e6 commit b27a929

File tree

4 files changed

+67
-6
lines changed

4 files changed

+67
-6
lines changed

.github/workflows/image-build.yml

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ on:
55

66
env:
77
USER: ${{secrets.DOCKER_USER}}
8+
IMAGE_NAME: docker-test
89

910
jobs:
1011
docker_build:
@@ -26,8 +27,8 @@ jobs:
2627
password: ${{secrets.DOCKER_PAT}}
2728
- name: Build and push
2829
run: |
29-
docker build --tag ${{env.USER}}/docker-uname:${{matrix.arch}} .
30-
docker push ${{env.USER}}/docker-uname:${{matrix.arch}}
30+
docker build --tag ${{env.USER}}/${{env.IMAGE_NAME}}:${{matrix.arch}} .
31+
docker push ${{env.USER}}/${{env.IMAGE_NAME}}:${{matrix.arch}}
3132
3233
docker_manifest:
3334
needs: docker_build
@@ -40,5 +41,27 @@ jobs:
4041
password: ${{secrets.DOCKER_PAT}}
4142
- name: Create and push manifest
4243
run: |
43-
docker manifest create ${{env.USER}}/docker-uname ${{env.USER}}/docker-uname:amd64 ${{env.USER}}/docker-uname:arm64
44-
docker manifest push ${{env.USER}}/docker-uname
44+
docker manifest create ${{env.USER}}/${{env.IMAGE_NAME}} ${{env.USER}}/${{env.IMAGE_NAME}}:amd64 ${{env.USER}}/${{env.IMAGE_NAME}}:arm64
45+
docker manifest push ${{env.USER}}/${{env.IMAGE_NAME}}
46+
47+
docker_test:
48+
needs: docker_manifest
49+
runs-on: ${{ matrix.os }}
50+
strategy:
51+
matrix:
52+
include:
53+
- os: ubuntu-24.04
54+
arch: amd64
55+
- os: ubuntu-24.04-arm
56+
arch: arm64
57+
steps:
58+
- name: Run Docker and check output
59+
run: |
60+
docker run -d --name ${{env.IMAGE_NAME}} --rm ${{env.USER}}/${{env.IMAGE_NAME}}:latest
61+
sleep 5 # Wait for the container to start
62+
output=$(docker exec ${{env.IMAGE_NAME}} wget -qO- localhost:8080)
63+
if [[ "$output" != "Hello from image NODE:, POD:, CPU PLATFORM:linux/${{matrix.arch}}" ]]; then
64+
echo "Unexpected output: $output"
65+
exit 1
66+
fi
67+
echo "Expected output received: $output"

Dockerfile

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,19 @@
1-
FROM ubuntu:latest
2-
CMD echo -n "Architecture is " && uname -m
1+
#
2+
# Build: 1st stage
3+
#
4+
FROM golang:1.24-alpine AS builder
5+
WORKDIR /app
6+
COPY go.mod .
7+
COPY hello.go .
8+
RUN go build -o /hello && \
9+
apk add --update --no-cache file && \
10+
file /hello
11+
12+
#
13+
# Release: 2nd stage
14+
#
15+
FROM alpine
16+
WORKDIR /
17+
COPY --from=builder /hello /hello
18+
RUN apk add --update --no-cache file
19+
CMD [ "/hello" ]

go.mod

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
module example.com/arm
2+
go 1.21

hello.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
"log"
6+
"net/http"
7+
"os"
8+
"runtime"
9+
)
10+
11+
func handler(w http.ResponseWriter, r *http.Request) {
12+
fmt.Fprintf(w, "Hello from image NODE:%s, POD:%s, CPU PLATFORM:%s/%s",
13+
os.Getenv("NODE_NAME"), os.Getenv("POD_NAME"), runtime.GOOS, runtime.GOARCH)
14+
}
15+
16+
func main() {
17+
http.HandleFunc("/", handler)
18+
log.Fatal(http.ListenAndServe(":8080", nil))
19+
}

0 commit comments

Comments
 (0)