Skip to content

Commit

Permalink
Support for docker
Browse files Browse the repository at this point in the history
  • Loading branch information
mactat committed May 31, 2023
1 parent e9143c7 commit cbe0124
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 31 deletions.
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
README.md
pipelines/
dockerfiles/
docs/
build/
LICENSE
18 changes: 17 additions & 1 deletion .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,22 @@ jobs:
run: make release-win
- name: "Build for macos"
run: "make release-mac"
- name: "Clean"
run: "make clean"
- uses: ncipollo/release-action@v1
with:
artifacts: "build/*"
artifacts: "build/*"

build_and_push_image:
name: Build and Push Docker image to Docker Hub
runs-on: ubuntu-latest
steps:
- name: Check out the repo
uses: actions/checkout@v3
- name: Log in to Docker Hub
uses: docker/login-action@f4ef78c080cd8ba55a85445d5b36e214a81df20a
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_TOKEN }}
- name: Build Tag and push
run: "make release-docker"
38 changes: 24 additions & 14 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Definitions
ROOT := $(PWD)
GO_VERSION := 1.20.4
ALPINE_VERSION := 3.18
OS := linux
ARCH := amd64

Expand All @@ -11,38 +12,47 @@ version:

.PHONY: build-docker
build-docker:
docker build -t mactat/framed -f ./dockerfiles/dev.dockerfile .
docker build \
-t mactat/framed \
-f ./dockerfiles/dockerfile \
--build-arg GO_VERSION=$(GO_VERSION) \
--build-arg ALPINE_VERSION=$(ALPINE_VERSION) \
.

.PHONY: release-docker
release-docker: version build-docker
docker tag mactat/framed mactat/framed:$(VERSION)
docker tag mactat/framed mactat/framed:alpine-$(ALPINE_VERSION)-$(VERSION)
docker push mactat/framed:$(VERSION)
docker push mactat/framed:alpine-$(ALPINE_VERSION)-$(VERSION)
docker push mactat/framed:latest

.PHONY: build-in-docker
build-in-docker:
build-in-docker: clean version
docker run \
--rm \
-v $(ROOT):/app \
--env GOOS=$(OS) \
--env GOARCH=$(ARCH) \
golang:$(GO_VERSION)-alpine3.18 \
golang:$(GO_VERSION)-alpine$(ALPINE_VERSION) \
/bin/sh -c "cd /app && go build -o ./build/ ./framed.go"
sudo chown -R $(USER):$(USER) ./build
cd ./build && \
tar -zcvf \
./framed-$(OS)-$(ARCH)-$(VERSION).tar.gz \
./framed$(if $(filter $(OS),windows),.exe)

.PHONY: release-lin
release-lin: version
release-lin:
$(MAKE) build-in-docker OS=linux ARCH=amd64
cd ./build && tar -zcvf ./framed-linux-$(VERSION).tar.gz ./framed
$(MAKE) clean

# make release for windows
.PHONY: release-win
release-win: version
release-win:
$(MAKE) build-in-docker OS=windows ARCH=amd64
cd ./build && tar -zcvf ./framed-windows-$(VERSION).tar.gz ./framed.exe
$(MAKE) clean

# make release for mac
.PHONY: release-mac
release-mac: version
release-mac:
$(MAKE) build-in-docker OS=darwin ARCH=amd64
cd ./build && tar -zcvf ./framed-macos-$(VERSION).tar.gz ./framed
$(MAKE) clean

.PHONY: build
build:
Expand Down
17 changes: 16 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,21 @@ Currently available examples:

See [examples](./examples) for more details.

## Running from docker
To run framed from docker, run the following command:

```bash
docker run --rm -v $(pwd):/app --user $(id -u):$(id -g) mactat/framed framed <command>
```

example:

```bash
docker run --rm -v $(pwd):/app --user $(id -u):$(id -g) mactat/framed framed import --example python
```

Images can be found on [dockerhub](https://hub.docker.com/r/mactat/framed).

## Demo

![Demo](./docs/static/demo.gif)
Expand All @@ -219,7 +234,7 @@ See [examples](./examples) for more details.
template: https://yourfile.com/framed.yaml # Share templates between projects
```
- [ ] Add some unit tests and integration tests
- [ ] Add some unit tests
- [ ] Add contributing guidelines
- [ ] Add more examples
- [ ] Create a github action for running tests
15 changes: 0 additions & 15 deletions dockerfiles/dev.dockerfile

This file was deleted.

17 changes: 17 additions & 0 deletions dockerfiles/dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
ARG GO_VERSION=1.20.4
ARG ALPINE_VERSION=3.18

FROM golang:${GO_VERSION}-alpine${ALPINE_VERSION} as builder

WORKDIR /app
COPY go.mod go.sum ./
RUN go mod download
COPY . .
RUN go build -o framed ./framed.go

FROM alpine:${ALPINE_VERSION} as release

COPY --from=builder /app/framed /bin/framed

WORKDIR /app
CMD ["/bin/sh"]

0 comments on commit cbe0124

Please sign in to comment.