diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml new file mode 100644 index 0000000..790f5b8 --- /dev/null +++ b/.github/workflows/docker.yml @@ -0,0 +1,34 @@ +name: docker-image +on: + workflow_dispatch: + +permissions: + pull-requests: write + packages: write + contents: write + actions: write + +jobs: + release: + name: Release + runs-on: ubuntu-latest + steps: + - name: Check out code into the Go module directory + uses: actions/checkout@v4 + + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Docker Login + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: $GITHUB_ACTOR + password: ${{ secrets.GITHUB_TOKEN }} + + - name: docker + run: | + make docker-build-push-all diff --git a/Dockerfile b/Dockerfile index e109a7a..af93c96 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,4 +2,5 @@ FROM golang:1.22.3-bookworm AS builder WORKDIR /app RUN git clone https://github.com/fujiwara/aws-sdk-client-go.git . RUN rm -f gen.yaml + ENTRYPOINT ["./build-in-docker.sh"] diff --git a/Makefile b/Makefile index 2e0bce2..b19c354 100644 --- a/Makefile +++ b/Makefile @@ -24,3 +24,11 @@ test: packages: goreleaser build --skip=validate --clean + +docker-build-and-push: Dockerfile + docker buildx build \ + --platform=linux/amd64,linux/arm64 \ + -t ghcr.io/fujiwara/aws-sdk-client-go:builder \ + -f Dockerfile \ + --push \ + . diff --git a/README.md b/README.md index 1615856..f2776db 100644 --- a/README.md +++ b/README.md @@ -57,7 +57,7 @@ services: Keys of `services` are AWS service names (`github.com/aws/aws-sdk-go-v2/service/*`), and values are method names of the service client (for example, `s3` is [s3.Client](https://pkg.go.dev/github.com/aws/aws-sdk-go-v2/service/s3#Client)). If you don't specify the method names, all methods of the service client are generated. -### Build the client +### Build on your machine To build the client, run the following commands (or simply run `make`): @@ -71,6 +71,34 @@ $ go build -o your-client ./cmd/aws-sdk-client-go/main.go If you change the configuration, run `make clean` before `make` to purge the generated files. +### Build with Docker + +`ghcr.io/fujiwara/aws-sdk-client-go:builder` is a Docker image that contains the Go environment. You can build the client in the container. + +Environment variables: +- `GIT_REF`: Git reference to checkout the repository. Default is `main`. You can specify a branch, tag, or commit hash. + +Example of use `AWS_SDK_CLIENT_GO_GEN` environment variable: +```console +$ docker run -it -e AWS_SDK_CLIENT_GO_GEN=ecs,firehose,s3 ghcr.io/fujiwara/aws-sdk-client-go:builder +... +``` + +Example of `gen.yaml` configuration file: +```console +$ docker run -it -v $(pwd)/gen.yaml:/app/gen.yaml ghcr.io/fujiwara/aws-sdk-client-go:builder +... +Completed. Please extract /app/aws-sdk-client-go from this container! +For example, run the following command: +docker cp $(docker ps -lq):/app/aws-sdk-client-go . +``` + +After the build is completed, the built binary is in the container. You can copy it to your host machine with `docker cp` command. + +```console +$ docker cp $(docker ps -lq):/app/aws-sdk-client-go . +``` + ## Performance comparison Example of execution `sts get-caller-identity` on 0.25vCPU Fargate(AMD64).