Skip to content

Commit

Permalink
Del Exercise, README, workflows
Browse files Browse the repository at this point in the history
  • Loading branch information
aceberg committed Dec 18, 2023
1 parent 9a3e04b commit a3a774b
Show file tree
Hide file tree
Showing 11 changed files with 227 additions and 13 deletions.
27 changes: 27 additions & 0 deletions .github/workflows/binary-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Binary-release

on:
workflow_dispatch:
release:
types: [created]

jobs:
generate:
name: Create release-artifacts
runs-on: ubuntu-latest
steps:
- name: Checkout the repository
uses: actions/checkout@master

- uses: actions/setup-go@v4
with:
go-version: 'stable'
- run: go version

- uses: goreleaser/goreleaser-action@v5
with:
distribution: goreleaser
version: latest
args: release --clean
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
26 changes: 26 additions & 0 deletions .github/workflows/dev-docker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: Dev-Docker

on:
workflow_dispatch:

env:
IMAGE_NAME: exercisediary
TAGS: dev


jobs:
build:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Build and Push Docker Image to docker.io
uses: mr-smithers-excellent/docker-build-push@v5
with:
image: ${{ secrets.DOCKER_USERNAME }}/${{ env.IMAGE_NAME }}
tags: ${{ env.TAGS }}
registry: docker.io
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
57 changes: 57 additions & 0 deletions .github/workflows/main-docker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
name: Main-Docker

on:
workflow_dispatch:
# push:
# branches: [ "main" ]
# paths:
# - 'Dockerfile'
# - 'src/**'

env:
IMAGE_NAME: exercisediary

jobs:
build:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Get version tag from env file
uses: c-py/action-dotenv-to-setenv@v2
with:
env-file: .version

- name: Set up QEMU
uses: docker/setup-qemu-action@v2

- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v2

- name: Login to GHCR
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Login to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}

- name: Build and push
uses: docker/build-push-action@v4
with:
context: .
platforms: linux/amd64,linux/arm/v7,linux/arm64
push: true
tags: |
${{ secrets.DOCKER_USERNAME }}/${{ env.IMAGE_NAME }}:latest
${{ secrets.DOCKER_USERNAME }}/${{ env.IMAGE_NAME }}:${{ env.VERSION }}
ghcr.io/${{ secrets.DOCKER_USERNAME }}/${{ env.IMAGE_NAME }}:latest
ghcr.io/${{ secrets.DOCKER_USERNAME }}/${{ env.IMAGE_NAME }}:${{ env.VERSION }}
28 changes: 28 additions & 0 deletions .github/workflows/readme-dockerhub.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Readme-DockerHub

on:
workflow_dispatch:
push:
branches: [ "main" ]
paths:
- 'README.md'

env:
IMAGE_NAME: exercisediary

jobs:
build:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Sync README.md to DockerHub
uses: ms-jpq/sync-dockerhub-readme@v1
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
repository: ${{ secrets.DOCKER_USERNAME }}/${{ env.IMAGE_NAME }}
readme: "./README.md"

6 changes: 2 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,11 @@ COPY . /src
RUN cd /src/cmd/ExerciseDiary/ && CGO_ENABLED=0 go build -o /ExerciseDiary .


FROM alpine
FROM scratch

WORKDIR /data/ExerciseDiary
WORKDIR /app

RUN apk add --no-cache arp-scan tzdata \
&& mkdir /data/ExerciseDiary

COPY --from=builder /ExerciseDiary /app/

ENTRYPOINT ["./ExerciseDiary"]
55 changes: 55 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
[![Main-Docker](https://github.com/aceberg/exercisediary/actions/workflows/main-docker.yml/badge.svg)](https://github.com/aceberg/exercisediary/actions/workflows/main-docker.yml)
[![Go Report Card](https://goreportcard.com/badge/github.com/aceberg/exercisediary)](https://goreportcard.com/report/github.com/aceberg/exercisediary)
[![Maintainability](https://api.codeclimate.com/v1/badges/e8f67994120fc7936aeb/maintainability)](https://codeclimate.com/github/aceberg/exercisediary/maintainability)
![Docker Image Size (latest semver)](https://img.shields.io/docker/image-size/aceberg/exercisediary)

<h1><a href="https://github.com/aceberg/exercisediary">
<img src="https://raw.githubusercontent.com/aceberg/exercisediary/main/assets/logo.png" width="35" />
</a>Exercise Diary</h1>

Light and easy workout diary

- [Quick start](https://github.com/aceberg/exercisediary#quick-start)
- [Config](https://github.com/aceberg/exercisediary#config)
- [Options](https://github.com/aceberg/exercisediary#options)
- [Thanks](https://github.com/aceberg/exercisediary#thanks)


![Screenshot](https://raw.githubusercontent.com/aceberg/exercisediary/main/assets/Screenshot%202023-04-02%20at%2022-27-40%20Resource%20Diary.png)

## Quick start

```sh
docker run --name exercisediary \
-e "TZ=Asia/Novosibirsk" \
-v ~/.dockerdata/ExerciseDiary:/data/ExerciseDiary \
-p 8851:8851 \
aceberg/exercisediary
```
<!-- Or use [docker-compose.yml](docker-compose.yml) -->


## Config


Configuration can be done through config file or environment variables

| Variable | Description | Default |
| -------- | ----------- | ------- |
| HOST | Listen address | 0.0.0.0 |
| PORT | Port for web GUI | 8851 |
| THEME | Any theme name from https://bootswatch.com in lowcase | grass |
| COLOR | Background color: light or dark | light |
| TZ | Set your timezone for correct time | "" |

## Options

| Key | Description | Default |
| -------- | ----------- | ------- |
| -c | Path to config file | /data/exercisediary/config.yaml |

## Thanks
- All go packages listed in [dependencies](https://github.com/aceberg/exercisediary/network/dependencies)
- [Bootstrap](https://getbootstrap.com/)
- Themes: [Free themes for Bootstrap](https://bootswatch.com)
- Favicon and logo: [Flaticon](https://www.flaticon.com/icons/)
2 changes: 1 addition & 1 deletion internal/conf/getconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ func Get(path string) models.Conf {
var config models.Conf

viper.SetDefault("HOST", "0.0.0.0")
viper.SetDefault("PORT", "8830")
viper.SetDefault("PORT", "8851")
viper.SetDefault("THEME", "grass")
viper.SetDefault("COLOR", "light")

Expand Down
4 changes: 2 additions & 2 deletions internal/db/sqlite.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func SelectEx(path string) (exes []models.Exercise) {

mu.Lock()
dbx := connect(path)
err := dbx.Select(&exes, "SELECT * FROM exercises ORDER BY ID DESC")
err := dbx.Select(&exes, "SELECT * FROM exercises ORDER BY ID ASC")
mu.Unlock()

check.IfError(err)
Expand All @@ -49,7 +49,7 @@ func SelectSet(path string) (sets []models.Set) {

mu.Lock()
dbx := connect(path)
err := dbx.Select(&sets, "SELECT * FROM sets ORDER BY ID DESC")
err := dbx.Select(&sets, "SELECT * FROM sets ORDER BY ID ASC")
mu.Unlock()

check.IfError(err)
Expand Down
25 changes: 21 additions & 4 deletions internal/web/exercise.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (

func exerciseHandler(c *gin.Context) {
var guiData models.GuiData
var id int

exData.Exs = db.SelectEx(appConfig.DBPath)

Expand All @@ -23,8 +24,8 @@ func exerciseHandler(c *gin.Context) {
idStr, ok := c.GetQuery("id")
log.Println("ID =", idStr)

if ok && (idStr != new) {
id, _ := strconv.Atoi(id)
if ok && (idStr != "new") {
id, _ = strconv.Atoi(idStr)

for _, oneEx := range exData.Exs {
if oneEx.ID == id {
Expand All @@ -45,17 +46,33 @@ func saveExerciseHandler(c *gin.Context) {
oneEx.Name = c.PostForm("name")
oneEx.Descr = c.PostForm("descr")

// id := c.PostForm("id")
id := c.PostForm("id")
weight := c.PostForm("weight")
reps := c.PostForm("reps")

oneEx.ID, _ = strconv.Atoi(id)
oneEx.Weight, _ = strconv.Atoi(weight)
oneEx.Reps, _ = strconv.Atoi(reps)

log.Println("ONEEX =", oneEx)

if oneEx.ID != 0 {
db.DeleteEx(appConfig.DBPath, oneEx.ID)
}

db.InsertEx(appConfig.DBPath, oneEx)
exData.Exs = db.SelectEx(appConfig.DBPath)

c.Redirect(http.StatusFound, "/exercise/")
c.Redirect(http.StatusFound, "/")
}

func deleteExerciseHandler(c *gin.Context) {

idStr := c.PostForm("id")
id, _ := strconv.Atoi(idStr)

db.DeleteEx(appConfig.DBPath, id)
exData.Exs = db.SelectEx(appConfig.DBPath)

c.Redirect(http.StatusFound, "/")
}
9 changes: 7 additions & 2 deletions internal/web/templates/exercise.html
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,14 @@
</tr>
<tr>
<td><button type="submit" class="btn btn-primary">Save</button></td>
<td></td>
</tr>
</form>
<form action="/exdel/" method="post">
<input name="id" type="hidden" value="{{ .OneEx.ID }}">
<td>
<button style="float: right;" type="submit" class="btn btn-danger">Delete</button>
</td>
</form>
</tr>
</table>
</div>
</div>
Expand Down
1 change: 1 addition & 0 deletions internal/web/webgui.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ func Gui(dirPath, nodePath string) {
router.POST("/config/", saveConfigHandler) // config.go
router.GET("/exercise/", exerciseHandler) // exercise.go
router.POST("/exercise/", saveExerciseHandler) // exercise.go
router.POST("/exdel/", deleteExerciseHandler) // exercise.go
router.POST("/set/", setHandler) // set.go

err := router.Run(address)
Expand Down

0 comments on commit a3a774b

Please sign in to comment.