From 82f3928bdb9fddf9e9514cdb564c91ddf5dabfd6 Mon Sep 17 00:00:00 2001 From: Rene Roscher Date: Sat, 25 Nov 2023 11:26:56 +0100 Subject: [PATCH] added build workflow --- .github/workflows/image-build.yml | 51 +++++++++++++++++++++++++++++++ Dockerfile | 24 +++++++++++++++ 2 files changed, 75 insertions(+) create mode 100644 .github/workflows/image-build.yml create mode 100644 Dockerfile diff --git a/.github/workflows/image-build.yml b/.github/workflows/image-build.yml new file mode 100644 index 0000000..824b7c3 --- /dev/null +++ b/.github/workflows/image-build.yml @@ -0,0 +1,51 @@ +name: Build and Deploy + +on: + push: + branches: + - '*' + +env: + IMAGE_NAME: nuxt3-tailwind-boiler + +jobs: + auth-test: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + + - name: Login to GitHub Container Registry + uses: docker/login-action@v1 + with: + registry: ghcr.io + username: ${{ github.repository_owner }} + password: ${{ secrets.DOCKER_REGISTRY_TOKEN }} + + build-and-push: + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v3 + + - name: Login to GitHub Container Registry + uses: docker/login-action@v2 + with: + registry: ghcr.io + username: ${{ github.repository_owner }} + password: ${{ secrets.DOCKER_REGISTRY_TOKEN }} + + - name: Build and push Docker image + run: | + docker build . --file Dockerfile --tag $IMAGE_NAME + IMAGE_ID=ghcr.io/${{ github.repository_owner }}/$IMAGE_NAME + IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]') + VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,') + COMMIT=$(echo "${{ github.sha }}") + [[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION=$(echo $VERSION | sed -e 's/^v//') + [ "$VERSION" == "main" ] && VERSION=latest + docker tag $IMAGE_NAME $IMAGE_ID:$VERSION + docker tag $IMAGE_NAME $IMAGE_ID:$COMMIT + docker push $IMAGE_ID:$VERSION + docker push $IMAGE_ID:$COMMIT diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..a6f5e8d --- /dev/null +++ b/Dockerfile @@ -0,0 +1,24 @@ +# Build +FROM node:lts-alpine AS build-stage + +WORKDIR /app + +COPY package.json yarn.lock ./ +RUN yarn install --frozen-lockfile + +COPY . . + +RUN yarn build + +# Production +FROM node:lts-alpine AS production-stage + +WORKDIR /app + +COPY --from=build-stage /app/.output ./.output + +RUN yarn install --frozen-lockfile --production + +EXPOSE 3000 + +CMD ["node", ".output/server/index.mjs"]