Skip to content

Commit

Permalink
Build images and publish to GHCR (#15)
Browse files Browse the repository at this point in the history
* push built images to docker registry

* build images and publish to ghcr

* fix gh action syntax

* split workflows

* install dev dependencies for building
  • Loading branch information
Kruemmelspalter authored Dec 26, 2022
1 parent c95eb0c commit a3cad66
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 11 deletions.
5 changes: 3 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@ jobs:

steps:
- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v3
- name: Cache gradle
uses: actions/cache@v2
uses: actions/cache@v3
id: gradle-cache
with:
path: backend/.gradle
Expand All @@ -76,3 +76,4 @@ jobs:

- name: Run tests
run: cd backend && ./gradlew test

18 changes: 18 additions & 0 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: Docker CI

on:
- push

jobs:
push:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest]
node: [lts/*]

steps:
- uses: actions/checkout@v3
- run: echo ${{ secrets.GH_PAT }} | docker login ghcr.io -u ${{ secrets.GH_USERNAME }} --password-stdin
- run: cd frontend && yarn install
- run: make push
30 changes: 24 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
commitHash := $(shell git rev-parse --short HEAD)
branchName := $(shell git rev-parse --abbrev-ref HEAD)
tagName := $(shell git describe --abbrev=0)

lint:
make -C frontend lint
make -C backend lint
Expand All @@ -10,11 +14,25 @@ build:
make -C frontend build
make -C backend build

docker:
make -C frontend build
docker: build
make -C backend docker

run:
make -C frontend build
make -C backend build
docker-compose up --build filespider
run: docker
docker-compose up --force-recreate filespider

push: docker
docker push ghcr.io/kruemmelspalter/filespider-backend:$(commitHash)

docker tag ghcr.io/kruemmelspalter/filespider-backend:$(commitHash) ghcr.io/kruemmelspalter/filespider-backend:$(branchName)
docker push ghcr.io/kruemmelspalter/filespider-backend:$(branchName)

ifeq "$(branchName)" "main"
docker tag ghcr.io/kruemmelspalter/filespider-backend:$(commitHash) ghcr.io/kruemmelspalter/filespider-backend:latest
docker push ghcr.io/kruemmelspalter/filespider-backend:main
endif
ifneq "$(tagName)" ""
docker tag ghcr.io/kruemmelspalter/filespider-backend:$(commitHash) ghcr.io/kruemmelspalter/filespider-backend:$(tagName)
docker push ghcr.io/kruemmelspalter/filespider-backend:$(tagName)
docker tag ghcr.io/kruemmelspalter/filespider-backend:$(commitHash) ghcr.io/kruemmelspalter/filespider-backend:stable
docker push ghcr.io/kruemmelspalter/filespider-backend:stable
endif
4 changes: 2 additions & 2 deletions backend/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ app/build/distributions/app.tar: $(shell find app/src/main/kotlin/me/kruemmelspa
./gradlew build

docker: app/build/distributions/app.tar
docker build . -t filespider-backend
docker build . -t ghcr.io/kruemmelspalter/filespider-backend:$(shell git rev-parse --short HEAD)

run: docker
docker run --rm filespider-backend
docker run --rm ghcr.io/kruemmelspalter/filespider-backend

lint:
./gradlew ktlintKotlinScriptCheck
Expand Down
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ services:
- ./data/mysql:/var/lib/mysql

filespider:
build: ./backend
image: ghcr.io/kruemmelspalter/filespider-backend
# restart: unless-stopped
environment:
APP_OPTS: -Ddatabase.host=database -Ddatabase.username=user -Ddatabase.password=password -Ddatabase.database=database
Expand Down

0 comments on commit a3cad66

Please sign in to comment.