Skip to content

Commit

Permalink
ci: create alpine images to allow running commands inside the contain…
Browse files Browse the repository at this point in the history
…er (#992)

* feat: build alpine tag alongisde slim tag

* fix: warnings in Dockerfile

* docs: updated bash reference
  • Loading branch information
fmartingr authored Nov 1, 2024
1 parent 4a58ef0 commit 6b6d5f3
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 9 deletions.
23 changes: 18 additions & 5 deletions .github/workflows/_buildx.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,19 @@
name: "Build Docker"

on: workflow_call
on:
workflow_call:
inputs:
tag_prefix:
description: 'The tag prefix to use'
required: false
type: string
default: ''
dockerfile:
description: 'The Dockerfile to use'
required: false
type: string
default: 'Dockerfile'

jobs:
buildx:
runs-on: ubuntu-latest
Expand All @@ -22,7 +35,7 @@ jobs:
run: |
REPO=ghcr.io/${{ github.repository }}
TAG=$(git describe --tags)
echo "tag_flags=--tag $REPO:$TAG" >> $GITHUB_ENV
echo "tag_flags=--tag $REPO:${{ inputs.tag_prefix }}$TAG" >> $GITHUB_ENV
# New tagged version
- name: Prepare version push tags
Expand All @@ -36,18 +49,18 @@ jobs:
else
TAG2="latest"
fi
echo "tag_flags=--tag $REPO:$TAG --tag $REPO:$TAG2" >> $GITHUB_ENV
echo "tag_flags=--tag $REPO:${{ inputs.tag_prefix }}$TAG --tag $REPO:${{ inputs.tag_prefix }}$TAG2" >> $GITHUB_ENV
# Every pull request
- name: Prepare pull request tags
if: github.event_name == 'pull_request'
run: |
echo "tag_flags=--tag ${{ github.ref }}" >> $GITHUB_ENV
REPO=ghcr.io/${{ github.repository }}
echo "tag_flags=--tag $REPO:pr-${{ github.event.pull_request.number }}" >> $GITHUB_ENV
echo "tag_flags=--tag $REPO:${{ inputs.tag_prefix }}pr-${{ github.event.pull_request.number }}" >> $GITHUB_ENV
- name: Buildx
run: |
set -x
echo "${{ secrets.GITHUB_TOKEN }}" | docker login -u "${{ github.repository_owner }}" --password-stdin ghcr.io
make buildx CONTAINER_BUILDX_OPTIONS="--push ${{ env.tag_flags }}"
make buildx CONTAINERFILE_NAME=${{ inputs.dockerfile }} CONTAINER_BUILDX_OPTIONS="--push ${{ env.tag_flags }}"
8 changes: 8 additions & 0 deletions .github/workflows/pull_request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,11 @@ jobs:
# only build on pull requests from the same repo for now
if: github.event.pull_request.head.repo.full_name == github.repository
uses: ./.github/workflows/_buildx.yml
call-buildx-alpine:
needs: call-gorelease
# only build on pull requests from the same repo for now
if: github.event.pull_request.head.repo.full_name == github.repository
uses: ./.github/workflows/_buildx.yml
with:
tag_prefix: alpine-
dockerfile: Dockerfile.alpine
8 changes: 8 additions & 0 deletions .github/workflows/push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,11 @@ jobs:
call-buildx:
needs: call-gorelease
uses: ./.github/workflows/_buildx.yml
call-buildx-alpine:
needs: call-gorelease
# only build on pull requests from the same repo for now
if: github.event.pull_request.head.repo.full_name == github.repository
uses: ./.github/workflows/_buildx.yml
with:
tag_prefix: alpine-
dockerfile: Dockerfile.alpine
8 changes: 8 additions & 0 deletions .github/workflows/version_bump.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,11 @@ jobs:
call-buildx:
needs: call-gorelease
uses: ./.github/workflows/_buildx.yml
call-buildx-alpine:
needs: call-gorelease
# only build on pull requests from the same repo for now
if: github.event.pull_request.head.repo.full_name == github.repository
uses: ./.github/workflows/_buildx.yml
with:
tag_prefix: alpine-
dockerfile: Dockerfile.alpine
5 changes: 2 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# Build stage
ARG ALPINE_VERSION
ARG GOLANG_VERSION
ARG ALPINE_VERSION=3.19

FROM docker.io/library/alpine:${ALPINE_VERSION} AS builder
ARG TARGETARCH
Expand All @@ -14,7 +13,7 @@ RUN apk add --no-cache ca-certificates tzdata && \
# Server image
FROM scratch

ENV PORT 8080
ENV PORT=8080
ENV SHIORI_DIR=/shiori
WORKDIR ${SHIORI_DIR}

Expand Down
23 changes: 23 additions & 0 deletions Dockerfile.alpine
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
ARG ALPINE_VERSION=3.19

FROM docker.io/library/alpine:${ALPINE_VERSION}
ARG TARGETARCH
ARG TARGETOS
ARG TARGETVARIANT
COPY dist/shiori_${TARGETOS}_${TARGETARCH}${TARGETVARIANT}/shiori /usr/bin/shiori
RUN apk add --no-cache ca-certificates tzdata && \
chmod +x /usr/bin/shiori && \
rm -rf /tmp/* && \
apk cache clean

ENV PORT=8080
ENV SHIORI_DIR=/shiori
WORKDIR ${SHIORI_DIR}

LABEL org.opencontainers.image.source="https://github.com/go-shiori/shiori"
LABEL maintainer="Felipe Martin <github@fmartingr.com>"

EXPOSE ${PORT}

ENTRYPOINT ["/usr/bin/shiori"]
CMD ["server"]
4 changes: 3 additions & 1 deletion docs/Usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,10 @@ The above command will :

After you've run the container in background, you can access console of the container:

> In order to be able to access the container and execute commands you need to use the `alpine-` prefixed images.
```
docker exec -it shiori sh
docker exec -it shiori ash
```

Now you can use `shiori` like normal. If you've finished, you can stop and remove the container by running :
Expand Down

0 comments on commit 6b6d5f3

Please sign in to comment.