Skip to content

Commit

Permalink
make image using Dockerfile // add gke auth plugin dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
morpheu committed Dec 8, 2023
1 parent f941f3b commit 188fe81
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 20 deletions.
48 changes: 29 additions & 19 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
- uses: actions/checkout@v2
- uses: actions/setup-go@v2
with:
go-version: 1.19
go-version: 1.20
- run: make test

publish:
Expand All @@ -24,27 +24,37 @@ jobs:
runs-on: ubuntu-latest
if: github.event_name != 'pull_request'
steps:
- uses: actions/checkout@v4
- uses: docker/setup-buildx-action@v3
- uses: actions/cache@v2
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildx-
- uses: Surgo/docker-smart-tag-action@v1
id: smarttag
with:
docker_image: ""
docker_image: "tsuru/acl-api"
default_branch: main
tag_with_sha: "true"
- uses: actions/setup-go@v2
- name: Handle smart-tag to proper tag var
uses: actions/github-script@v6
id: handle_tag
with:
go-version: 1.19
- uses: actions/checkout@v2

- uses: imjasonh/setup-ko@v0.6
env:
KO_DOCKER_REPO: tsuru
- env:
DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }}
DOCKERHUB_PASSWORD: ${{ secrets.DOCKERHUB_PASSWORD }}
KO_DEFAULTBASEIMAGE: alpine:3.17.1
TO_BUILD_TAG: ${{ steps.smarttag.outputs.tag }}
run: |
export TAGS=$(echo -n "${TO_BUILD_TAG}" | sed 's/://g')
echo "Lets build tags: ${TAGS}"
echo "${DOCKERHUB_PASSWORD}" | ko login docker.io --username ${DOCKERHUB_USERNAME} --password-stdin
ko build -B --platform linux/arm64,linux/amd64 -t ${TAGS}
script: |
var tag_re = /:/g
var orig_tags = `${{steps.smarttag.outputs.tag}}`
return orig_tags.replace(tag_re,"")
- uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}
- uses: docker/build-push-action@v5
with:
file: ./Dockerfile
push: true
tags: ${{ steps.handle_tag.outputs.result }}
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache
platforms: linux/amd64,linux/arm64
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@
*.dll
*.so
*.dylib
*.test
*.test
bin
17 changes: 17 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
FROM golang:1.20-alpine3.18 AS builder
COPY . /go/src/github.com/tsuru/acl-api
WORKDIR /go/src/github.com/tsuru/acl-api
RUN set -x \
&& apk add --update gcc git make musl-dev \
&& make build

FROM alpine:3.18
COPY --from=builder /go/src/github.com/tsuru/acl-api/bin/acl-api /bin/acl-api
ARG gke_auth_plugin_version=0.1.1
ARG TARGETARCH
RUN set -x \
&& apk add --update --no-cache curl ca-certificates \
&& curl -fsSL "https://github.com/traviswt/gke-auth-plugin/releases/download/${gke_auth_plugin_version}/gke-auth-plugin_Linux_$( [[ ${TARGETARCH} == 'amd64' ]] && echo 'x86_64' || echo ${TARGETARCH} ).tar.gz" \
| tar -C /usr/local/bin -xzvf- gke-auth-plugin \
&& gke-auth-plugin version
CMD ["/bin/acl-api"]
10 changes: 10 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
GO_BUILD_DIR ?= ./bin

.PHONY: fmt
fmt: ## Run go fmt against code.
go fmt ./...
Expand All @@ -9,3 +11,11 @@ vet: ## Run go vet against code.
.PHONY: test
test: fmt vet ## Run tests.
go test ./... -coverprofile cover.out

.PHONY: build
build: build-dirs
CGO_ENABLED=0 go build -o $(GO_BUILD_DIR)/

.PHONY: build-dirs
build-dirs:
@mkdir -p $(GO_BUILD_DIR)

0 comments on commit 188fe81

Please sign in to comment.