Skip to content

Commit

Permalink
ci: docker images
Browse files Browse the repository at this point in the history
  • Loading branch information
apotdevin committed Dec 11, 2021
1 parent f99f253 commit f694448
Show file tree
Hide file tree
Showing 6 changed files with 224 additions and 18 deletions.
20 changes: 14 additions & 6 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,11 @@ WORKDIR /app
# Set env variables
ARG BASE_PATH=""
ENV BASE_PATH=${BASE_PATH}
ARG NODE_ENV="production"
ENV NODE_ENV=${NODE_ENV}
ENV NEXT_TELEMETRY_DISABLED=1

# Build the NextJS application
# Build the NestJS and NextJS application
COPY . .
RUN npm run build

Expand All @@ -46,15 +48,21 @@ WORKDIR /app
# Set env variables
ARG BASE_PATH=""
ENV BASE_PATH=${BASE_PATH}
ARG NODE_ENV="production"
ENV NODE_ENV=${NODE_ENV}
ENV NEXT_TELEMETRY_DISABLED=1

COPY --from=build /app/package.json /app/package-lock.json /app/next.config.js ./
COPY --from=build /app/public ./public
COPY --from=build /app/package.json /app/package-lock.json ./
COPY --from=build /app/node_modules/ ./node_modules

# Copy NextJS files
COPY --from=build /app/src/client/public ./src/client/public
COPY --from=build /app/src/client/next.config.js ./src/client/
COPY --from=build /app/.next/ ./.next

COPY ./scripts/initCookie.sh ./scripts/initCookie.sh
# Copy NestJS files
COPY --from=build /app/dist/ ./dist

EXPOSE 3000
EXPOSE 3000

CMD [ "npm", "start" ]
CMD [ "npm", "run", "start:prod" ]
20 changes: 14 additions & 6 deletions arm32v7.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,11 @@ WORKDIR /app
# Set env variables
ARG BASE_PATH=""
ENV BASE_PATH=${BASE_PATH}
ARG NODE_ENV="production"
ENV NODE_ENV=${NODE_ENV}
ENV NEXT_TELEMETRY_DISABLED=1

# Build the NextJS application
# Build the NestJS and NextJS application
COPY . .
RUN npm run build

Expand All @@ -46,15 +48,21 @@ WORKDIR /app
# Set env variables
ARG BASE_PATH=""
ENV BASE_PATH=${BASE_PATH}
ARG NODE_ENV="production"
ENV NODE_ENV=${NODE_ENV}
ENV NEXT_TELEMETRY_DISABLED=1

COPY --from=build /app/package.json /app/package-lock.json /app/next.config.js ./
COPY --from=build /app/public ./public
COPY --from=build /app/package.json /app/package-lock.json ./
COPY --from=build /app/node_modules/ ./node_modules

# Copy NextJS files
COPY --from=build /app/src/client/public ./src/client/public
COPY --from=build /app/src/client/next.config.js ./src/client/
COPY --from=build /app/.next/ ./.next

COPY ./scripts/initCookie.sh ./scripts/initCookie.sh
# Copy NestJS files
COPY --from=build /app/dist/ ./dist

EXPOSE 3000
EXPOSE 3000

CMD [ "npm", "start" ]
CMD [ "npm", "run", "start:prod" ]
20 changes: 14 additions & 6 deletions arm64v8.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,11 @@ WORKDIR /app
# Set env variables
ARG BASE_PATH=""
ENV BASE_PATH=${BASE_PATH}
ARG NODE_ENV="production"
ENV NODE_ENV=${NODE_ENV}
ENV NEXT_TELEMETRY_DISABLED=1

# Build the NextJS application
# Build the NestJS and NextJS application
COPY . .
RUN npm run build

Expand All @@ -46,15 +48,21 @@ WORKDIR /app
# Set env variables
ARG BASE_PATH=""
ENV BASE_PATH=${BASE_PATH}
ARG NODE_ENV="production"
ENV NODE_ENV=${NODE_ENV}
ENV NEXT_TELEMETRY_DISABLED=1

COPY --from=build /app/package.json /app/package-lock.json /app/next.config.js ./
COPY --from=build /app/public ./public
COPY --from=build /app/package.json /app/package-lock.json ./
COPY --from=build /app/node_modules/ ./node_modules

# Copy NextJS files
COPY --from=build /app/src/client/public ./src/client/public
COPY --from=build /app/src/client/next.config.js ./src/client/
COPY --from=build /app/.next/ ./.next

COPY ./scripts/initCookie.sh ./scripts/initCookie.sh
# Copy NestJS files
COPY --from=build /app/dist/ ./dist

EXPOSE 3000
EXPOSE 3000

CMD [ "npm", "start" ]
CMD [ "npm", "run", "start:prod" ]
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@
"build": "npm run build:nest && npm run build:next",
"build:nest": "nest build",
"build:next": "cd src/client && next build",
"build:image": "docker build --no-cache -t apotdevin/thunderhub:test-amd64 .",
"build:32": "docker build --no-cache -f arm32v7.Dockerfile -t apotdevin/thunderhub:test-arm32v7 .",
"build:64": "docker build -f arm64v8.Dockerfile -t apotdevin/thunderhub:test-arm64v8 .",
"build:manifest": "docker manifest create apotdevin/thunderhub:test apotdevin/thunderhub:test-amd64 apotdevin/thunderhub:test-arm32v7 apotdevin/thunderhub:test-arm64v8",
"build:all": "sh ./scripts/buildAllImages.sh",
"format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"",
"start": "nest start",
"start:dev": "nest start --watch",
Expand Down
144 changes: 144 additions & 0 deletions scripts/buildAllImages.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
#!/bin/sh

REPO=apotdevin/thunderhub
BASE=base

echo
echo
echo "------------------------------------------"
echo "Building images for" $REPO
echo "------------------------------------------"
echo
echo

git checkout master || exit
git pull || exit

VERSION=$(git describe --tags --abbrev=0 2>&1)

git checkout $VERSION || exit

NOT_LATEST=false

echo "Do you want to build images for version" $VERSION "?"
select yn in "Yes" "No" "Specify"; do
case $yn in
Yes ) break;;
Specify) NOT_LATEST=true; break;;
No ) exit;;
esac
done

if [ "$NOT_LATEST" = true ]; then
read -p "Enter the version you want to build: " VERSION
git checkout $VERSION || exit
fi


START=`date +%s`

echo
echo
echo "------------------------------------------"
echo "Building amd64 image for version" $VERSION
echo "------------------------------------------"
echo
echo

docker build --pull -t $REPO:$VERSION-amd64 -f Dockerfile .
docker push $REPO:$VERSION-amd64

docker build --build-arg BASE_PATH='/thub' --pull -t $REPO:$BASE-$VERSION-amd64 -f Dockerfile .
docker push $REPO:$BASE-$VERSION-amd64

ENDAMD=`date +%s`

echo
echo
echo "------------------------------------------"
echo "Building arm32v7 image for version" $VERSION
echo "------------------------------------------"
echo
echo

docker build --pull -t $REPO:$VERSION-arm32v7 -f arm32v7.Dockerfile .
docker push $REPO:$VERSION-arm32v7

docker build --build-arg BASE_PATH='/thub' --pull -t $REPO:$BASE-$VERSION-arm32v7 -f arm32v7.Dockerfile .
docker push $REPO:$BASE-$VERSION-arm32v7

ENDARM32=`date +%s`

echo
echo
echo "------------------------------------------"
echo "Building arm64v8 image for version" $VERSION
echo "------------------------------------------"
echo
echo

docker build --pull -t $REPO:$VERSION-arm64v8 -f arm64v8.Dockerfile .
docker push $REPO:$VERSION-arm64v8

docker build --build-arg BASE_PATH='/thub' --pull -t $REPO:$BASE-$VERSION-arm64v8 -f arm64v8.Dockerfile .
docker push $REPO:$BASE-$VERSION-arm64v8

ENDARM64=`date +%s`

echo
echo
echo "------------------------------------------"
echo "Creating manifest for version" $VERSION
echo "------------------------------------------"
echo
echo

docker manifest create --amend $REPO:$VERSION $REPO:$VERSION-amd64 $REPO:$VERSION-arm32v7 $REPO:$VERSION-arm64v8
docker manifest annotate $REPO:$VERSION $REPO:$VERSION-amd64 --os linux --arch amd64
docker manifest annotate $REPO:$VERSION $REPO:$VERSION-arm32v7 --os linux --arch arm --variant v7
docker manifest annotate $REPO:$VERSION $REPO:$VERSION-arm64v8 --os linux --arch arm64 --variant v8
docker manifest push $REPO:$VERSION -p

echo
echo
echo "------------------------------------------"
echo "Creating manifest for version" $BASE $VERSION
echo "------------------------------------------"
echo
echo

docker manifest create --amend $REPO:$BASE-$VERSION $REPO:$BASE-$VERSION-amd64 $REPO:$BASE-$VERSION-arm32v7 $REPO:$BASE-$VERSION-arm64v8
docker manifest annotate $REPO:$BASE-$VERSION $REPO:$BASE-$VERSION-amd64 --os linux --arch amd64
docker manifest annotate $REPO:$BASE-$VERSION $REPO:$BASE-$VERSION-arm32v7 --os linux --arch arm --variant v7
docker manifest annotate $REPO:$BASE-$VERSION $REPO:$BASE-$VERSION-arm64v8 --os linux --arch arm64 --variant v8
docker manifest push $REPO:$BASE-$VERSION -p

echo
echo
echo "------------------------------------------"
echo "Build Stats"
echo "------------------------------------------"
echo
echo

RUNTIME=$((ENDAMD-START))
RUNTIME1=$((ENDARM32-ENDAMD))
RUNTIME2=$((ENDARM64-ENDARM32))

git checkout master
git pull

echo
echo
echo "------------------------------------------"
echo "DONE"
echo "------------------------------------------"
echo
echo
echo "Finished building and pushing images for" $REPO:$VERSION "and for" $REPO:$BASE-$VERSION
echo
echo "amd64 took" $RUNTIME "seconds"
echo "arm32v7 took" $RUNTIME1 "seconds"
echo "arm64v8 took" $RUNTIME2 "seconds"
echo
echo
33 changes: 33 additions & 0 deletions scripts/updateToLatest.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/bin/sh
# fetch latest master
echo "Checking for changes upstream ..."
git fetch
UPSTREAM=${1:-'@{u}'}
LOCAL=$(git rev-parse @)
REMOTE=$(git rev-parse "$UPSTREAM")

if [ $LOCAL = $REMOTE ]; then
TAG=$(git tag | sort -V | tail -1)
echo "You are up-to-date on version" $TAG
else
echo "Reseting repository..."
git reset --hard

echo "Pulling latest changes..."
git pull -p

# install deps
echo "Installing dependencies..."
npm install --quiet

# build nextjs
echo "Building application..."
npm run build

# remove useless deps
echo "Removing unneccesary modules..."
npm prune --production

TAG=$(git tag | sort -V | tail -1)
echo "Updated to version" $TAG
fi

0 comments on commit f694448

Please sign in to comment.