Skip to content

Commit

Permalink
add docker build and publish step
Browse files Browse the repository at this point in the history
  • Loading branch information
mput committed Feb 13, 2024
1 parent bf858f8 commit bfb2e6d
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 3 deletions.
25 changes: 22 additions & 3 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,30 @@ jobs:
run: |
sudo apt-get install -y ledger
- name: Build
run: go build -v ./...

- name: Test
run: go test -v ./...
env:
GITHUB_URL: ${{ secrets.GIT_URL }}
GITHUB_TOKEN: ${{ secrets.GIT_ACCESS_TOKEN }}

- name: set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v3

- name: build and publish image
if: ${{ github.ref == 'refs/heads/main' }}
env:
DOCKER_HUB_USER: ${{ secrets.DOCKER_HUB_USER }}
DOCKER_HUB_TOKEN: ${{ secrets.DOCKER_HUB_TOKEN }}
GITHUB_SHA: ${{ github.sha }}
GITHUB_REF: ${{ github.ref }}
run: |
ref="$(echo ${GITHUB_REF} | cut -d'/' -f3)"
version=${ref}-${GITHUB_SHA:0:7}-$(date -u +%Y-%m-%dT%H:%M:%S)
echo "GITHUB_REF=${GITHUB_REF}, GITHUB_SHA=${GITHUB_SHA}, GIT_BRANCH=${ref}"
echo "version=${version}"
echo ${DOCKER_HUB_TOKEN} | docker login -u ${DOCKER_HUB_USER} --password-stdin
docker buildx build --push \
--build-arg VERSION=${version} \
--platform linux/amd64,linux/arm/v7,linux/arm64 \
-t ${DOCKER_HUB_USER}/teledger:${ref} .
19 changes: 19 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
FROM golang:1.22.0-alpine as build


ADD ./ /repo
WORKDIR /repo

ARG VERSION=docker-dev
RUN echo go version: `go version`
RUN echo build version: ${VERSION}

RUN go build -o teledger -ldflags "-X main.version=${version} -s -w" ./app/main.go

FROM golang:1.22.0-alpine

WORKDIR /srv
RUN apk add --no-cache ledger=~3.3.2 && echo ledger: `which ledger`
COPY --from=build /repo/teledger /srv/teledger

CMD ["/srv/teledger"]

0 comments on commit bfb2e6d

Please sign in to comment.