Skip to content

Commit

Permalink
update with pro alpine
Browse files Browse the repository at this point in the history
  • Loading branch information
tom_taylor committed Oct 23, 2023
1 parent 9d728ee commit 4136aa6
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 10 deletions.
44 changes: 34 additions & 10 deletions .github/workflows/publish-docker-images.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ on:
paths:
- 'release-versions/*'

env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}

jobs:
build:
runs-on: ubuntu-latest
Expand All @@ -30,11 +34,18 @@ jobs:
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1

- name: Login to DockerHub
uses: docker/login-action@v1
- name: Log in to the Container registry
uses: docker/login-action@65b78e6e13532edd9afa3aa52ac7964289d1a9c1
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}

- name: Build (default => debian)
uses: docker/build-push-action@v2
Expand All @@ -46,9 +57,9 @@ jobs:
# platforms: linux/amd64,linux/arm64,linux/arm/v7
push: true
tags: |
${{ secrets.DOCKER_USERNAME }}/strapi:${{ steps.vars.outputs.tag }}
${{ secrets.DOCKER_USERNAME }}/strapi:latest
${{ steps.meta.outputs.tags }}:${{ steps.vars.outputs.tag }}
${{ steps.meta.outputs.tags }}:latest
- name: Build (alpine)
uses: docker/build-push-action@v2
with:
Expand All @@ -59,15 +70,28 @@ jobs:
# platforms: linux/amd64,linux/arm64,linux/arm/v7
push: true
tags: |
${{ secrets.DOCKER_USERNAME }}/strapi:${{ steps.vars.outputs.tag }}-alpine
${{ secrets.DOCKER_USERNAME }}/strapi:latest-alpine
${{ steps.meta.outputs.tags }}:${{ steps.vars.outputs.tag }}-alpine
${{ steps.meta.outputs.tags }}:latest-alpine
- name: Build (alpine-prod)
uses: docker/build-push-action@v2
with:
context: ./images/strapi-alpine
build-args: |
STRAPI_VERSION=${{ steps.vars.outputs.tag }}
NODE_VERSION=18
# platforms: linux/amd64,linux/arm64,linux/arm/v7
push: true
tags: |
${{ steps.meta.outputs.tags }}:${{ steps.vars.outputs.tag }}-alpine-prod
${{ steps.meta.outputs.tags }}:latest-alpine-prod
- name: Docker Hub Description (README.md)
uses: peter-evans/dockerhub-description@v2
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
repository: naskio/strapi
repository: TomTaylorCo/docker-strapi
readme-filepath: README.md

- name: Create Release in GitHub
Expand Down
41 changes: 41 additions & 0 deletions images/strapi-prod-alpine/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Creating multi-stage build for production
# This reduces the file size of the docker image for prod
# Also adds ability to change base uri for api

# BASE
ARG NODE_VERSION=18

FROM node:${NODE_VERSION}-alpine as build
RUN apk update && apk add --no-cache build-base gcc autoconf automake zlib-dev libpng-dev vips-dev git > /dev/null 2>&1
ENV NODE_ENV=production

ARG STRAPI_VERSION=latest
RUN yarn global add @strapi/strapi@${STRAPI_VERSION}

RUN mkdir -p /build/app && chown 1000:1000 -R /build/app

WORKDIR /build
COPY package.json yarn.lock ./
RUN yarn global add node-gyp
RUN NODE_TLS_REJECT_UNAUTHORIZED=0 yarn config set network-timeout 600000 -g && yarn install --production
ENV PATH /build/node_modules/.bin:$PATH
WORKDIR /build/app
COPY ./server.js ./config/server.js
RUN ls /build/app/config
RUN yarn build

# Creating final production image
FROM node:${NODE_VERSION}-alpine
RUN apk add --no-cache vips-dev
ENV NODE_ENV=production
RUN mkdir -p /srv/app && chown 1000:1000 -R /srv/app
WORKDIR /srv
COPY --from=build /build/node_modules ./node_modules
WORKDIR /srv/app
COPY --from=build /build/app ./
ENV PATH /build/node_modules/.bin:$PATH

RUN chown -R node:node /srv/app
USER node
EXPOSE 1337
CMD ["yarn", "start"]
3 changes: 3 additions & 0 deletions images/strapi-prod-alpine/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Strapi v4

Based on alpine.
11 changes: 11 additions & 0 deletions images/strapi-prod-alpine/server.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module.exports = ({ env }) => ({
host: env('HOST', '0.0.0.0'),
port: env.int('PORT', 1337),
url: env("URL", ""),
app: {
keys: env.array('APP_KEYS'),
},
webhooks: {
populateRelations: env.bool('WEBHOOKS_POPULATE_RELATIONS', false),
},
});

0 comments on commit 4136aa6

Please sign in to comment.