diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..e8ff656 --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,41 @@ +name: Build + +on: + push: + branches: + - main + +jobs: + build: + runs-on: ubuntu-latest + env: + CONTAINER_REGISTRY: ghcr.io + + steps: + - uses: actions/checkout@v4 + + - name: Build app + run: | + cd app + yarn install --immutable + yarn tsc + yarn build:backend --config ../../app-config.yaml --config ../../app-config.production.yaml + + - name: Get Docker image tag + id: image_tags + run: | + echo "tag=$CONTAINER_REGISTRY/$(echo $GITHUB_REPOSITORY | tr '[:upper:]' '[:lower:]'):$GITHUB_SHA" >> $GITHUB_OUTPUT + + - name: Login to GitHub Container Registry + uses: docker/login-action@v3 + with: + registry: ${{ env.CONTAINER_REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Docker build + run: | + cd app && docker image build . -f packages/backend/Dockerfile --tag $TAG + docker push $TAG + env: + TAG: ${{ steps.image_tags.outputs.tag }} diff --git a/app/Dockerfile b/app/Dockerfile deleted file mode 100644 index 4e9297c..0000000 --- a/app/Dockerfile +++ /dev/null @@ -1,55 +0,0 @@ -FROM node:20-bookworm-slim - -# Set Python interpreter for `node-gyp` to use -ENV PYTHON=/usr/bin/python3 - -# Install isolate-vm dependencies, these are needed by the @backstage/plugin-scaffolder-backend. -RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \ - --mount=type=cache,target=/var/lib/apt,sharing=locked \ - apt-get update && \ - apt-get install -y --no-install-recommends python3 g++ build-essential && \ - rm -rf /var/lib/apt/lists/* - -# Install sqlite3 dependencies. You can skip this if you don't use sqlite3 in the image, -# in which case you should also move better-sqlite3 to "devDependencies" in package.json. -RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \ - --mount=type=cache,target=/var/lib/apt,sharing=locked \ - apt-get update && \ - apt-get install -y --no-install-recommends libsqlite3-dev && \ - rm -rf /var/lib/apt/lists/* - -# From here on we use the least-privileged `node` user to run the backend. -USER node - -# This should create the app dir as `node`. -# If it is instead created as `root` then the `tar` command below will fail: `can't create directory 'packages/': Permission denied`. -# If this occurs, then ensure BuildKit is enabled (`DOCKER_BUILDKIT=1`) so the app dir is correctly created as `node`. -WORKDIR /app - -# Copy files needed by Yarn -COPY --chown=node:node .yarn ./.yarn -COPY --chown=node:node .yarnrc.yml ./ - -# This switches many Node.js dependencies to production mode. -ENV NODE_ENV=production - -# This disables node snapshot for Node 20 to work with the Scaffolder -ENV NODE_OPTIONS="--no-node-snapshot" - -# Copy repo skeleton first, to avoid unnecessary docker cache invalidation. -# The skeleton contains the package.json of each package in the monorepo, -# and along with yarn.lock and the root package.json, that's enough to run yarn install. -COPY --chown=node:node yarn.lock package.json packages/backend/dist/skeleton.tar.gz ./ -RUN tar xzf skeleton.tar.gz && rm skeleton.tar.gz - -RUN --mount=type=cache,target=/home/node/.cache/yarn,sharing=locked,uid=1000,gid=1000 \ - yarn workspaces focus --all --production && rm -rf "$(yarn cache clean)" - -# This will include the examples, if you don't need these simply remove this line -COPY --chown=node:node examples ./examples - -# Then copy the rest of the backend bundle, along with any other files we might want. -COPY --chown=node:node packages/backend/dist/bundle.tar.gz app-config*.yaml ./ -RUN tar xzf bundle.tar.gz && rm bundle.tar.gz - -CMD ["node", "packages/backend", "--config", "app-config.yaml", "--config", "app-config.production.yaml"] \ No newline at end of file