diff --git a/build-push-image/Dockerfile.gha-deploy b/build-push-image/Dockerfile.gha-deploy new file mode 100644 index 00000000..e020f529 --- /dev/null +++ b/build-push-image/Dockerfile.gha-deploy @@ -0,0 +1,36 @@ +# Create the image with Nginx environment. +FROM nginx:alpine + +# Copy results from the dist folder to the image. +ARG DIST_FOLDER +RUN [ -z "$DIST_FOLDER" ] && echo "DIST_FOLDER is required" && exit 1 || true +COPY $DIST_FOLDER /usr/share/nginx/html + +# Remove source maps from the production build +RUN find /usr/share/nginx/html -name "*.map" -type f -delete + +# Copy the entrypoint. +ARG ENV_RUNTIME_ENTRYPOINT +RUN [ -z "$ENV_RUNTIME_ENTRYPOINT" ] && echo "ENV_RUNTIME_ENTRYPOINT is required" && exit 1 || true +COPY $ENV_RUNTIME_ENTRYPOINT /usr/local/bin/env-runtime.entrypoint.sh +RUN chmod +x /usr/local/bin/env-runtime.entrypoint.sh + +# version is used in build process, so the value won't be available here otherwise +ARG VERSION +RUN [ -z "$VERSION" ] && echo "VERSION is required" && exit 1 || true +ENV DAVINCI_RELEASE_VERSION $VERSION + +RUN echo $VERSION > /usr/share/nginx/html/REVISION.txt + +# Copy configuration file for Nginx and replace the default one. +ARG NGINX_CONFIG +RUN [ -z "$NGINX_CONFIG" ] && echo "NGINX_CONFIG is required" && exit 1 || true +COPY $NGINX_CONFIG /etc/nginx/conf.d/default.conf.templ + +ARG HTML_CDN_CACHE_TAG="davinci-app" +ENV HTML_CDN_CACHE_TAG=${HTML_CDN_CACHE_TAG} + +# Entry point to provide Run Time Environment Variables for the App. +ENTRYPOINT ["/usr/local/bin/env-runtime.entrypoint.sh"] + +CMD ["nginx", "-g", "daemon off;"] diff --git a/build-push-image/README.md b/build-push-image/README.md index bf85459e..fce9b41f 100644 --- a/build-push-image/README.md +++ b/build-push-image/README.md @@ -12,15 +12,14 @@ This GH Action builds a Docker image and pushes to google cloud. The list of arguments, that are used in GH Action: -| name | type | required | default | description | -| ---------------- | ----------------------------------------------------------- | -------- | -------------------------------------------------------------- | ------------------------------------------------------------------------------------------- | -| `sha` | string | ✅ | | Commit hash that will be used as a tag for the Docker image | -| `image-name` | string | ✅ | | Name of the Docker image. Might be used in the next steps (for ex.: deploy a Docker image) | -| `environment` | enum<
`temploy`,
`staging`,
`production`,
> | | staging | Determines additional procedures while creating a Docker image. | -| `build-args` | string | ✅ | | Multiline string to describe build arguments that will be used during dockerization | -| `docker-file` | string | | ./davinci/packages/ci/src/configs/docker/Dockerfile.gha-deploy | pathname to Docker file | -| `davinci-branch` | string | | master | Custom davinci branch | -| `node-version` | string | | 18 | Node.js version used. The action is guaranteed to work only with Node.js@18 (default value) | +| name | type | required | default | description | +| ------------- | ----------------------------------------------------------- | -------- | ---------- | ------------------------------------------------------------------------------------------ | +| `sha` | string | ✅ | | Commit hash that will be used as a tag for the Docker image | +| `image-name` | string | ✅ | | Name of the Docker image. Might be used in the next steps (for ex.: deploy a Docker image) | +| `environment` | enum<
`temploy`,
`staging`,
`production`,
> | | staging | Determines additional procedures while creating a Docker image. | +| `build-args` | string | ✅ | | Multiline string to describe build arguments that will be used during dockerization | +| `docker-file` | string | | Dockerfile | pathname to Dockerfile | +| `tags` | string | | | Image Tags | ### Outputs @@ -31,10 +30,11 @@ Not specified All ENV Variables, defined in a GH Workflow are also passed to a GH Action. It means, the might be reused as is. This is a list of ENV Variables that are used in GH Action: -| name | description | -| ----------------- | -------------------------------------------------- | -| `GITHUB_TOKEN` | GitHub token. Is used to checkout `davinci` branch | -| `GCR_ACCOUNT_KEY` | Necessary token to push image to Google cloud | +| name | description | +| -------------------------- | -------------------------------------------------- | +| `GITHUB_TOKEN` | GitHub token. Is used to checkout `davinci` branch | +| `GCR_ACCOUNT_KEY` | Necessary token to push image to Google cloud | +| `TOPTAL_BUILD_BOT_SSH_KEY` | SSH key to access Google cloud | ### Usage diff --git a/build-push-image/action.yml b/build-push-image/action.yml index 5cf4d7f6..8b811a85 100644 --- a/build-push-image/action.yml +++ b/build-push-image/action.yml @@ -5,6 +5,7 @@ description: | envInputs: GITHUB_TOKEN: GitHub token. Is used to checkout `davinci` branch GCR_ACCOUNT_KEY: Necessary token to push image to Google cloud + TOPTAL_BUILD_BOT_SSH_KEY: SSH key to access Google cloud inputs: sha: @@ -21,35 +22,18 @@ inputs: required: true description: 'Multiline string to describe build arguments that will be used during dockerization' docker-file: - description: 'pathname to Docker file' + description: 'pathname to Dockerfile' required: false - default: ./davinci/packages/ci/src/configs/docker/Dockerfile.gha-deploy - davinci-branch: - description: 'Custom davinci branch' + default: Dockerfile + tags: + description: 'Image Tags' required: false - default: 'master' - node-version: - required: false - default: 18 - description: 'Node.js version used. The action is guaranteed to work only with Node.js@18 (default value)' runs: using: composite steps: - - name: Check out davinci - uses: actions/checkout@v3 - with: - repository: toptal/davinci - token: ${{ env.GITHUB_TOKEN }} - path: davinci - ref: ${{ inputs.davinci-branch }} - - - name: Set up node - uses: actions/setup-node@v3.2.0 - with: - node-version: ${{ inputs.node-version }} - - id: meta-latest + if: inputs.tags != '' shell: bash env: ENVIRONMENT: ${{ inputs.environment }} @@ -58,15 +42,22 @@ runs: echo latest=$latest >> $GITHUB_OUTPUT - name: Docker meta + if: inputs.tags != '' + uses: docker/metadata-action@v5 id: meta - uses: docker/metadata-action@v5.2.0 with: images: | us-central1-docker.pkg.dev/toptal-hub/containers/${{ inputs.image-name }} tags: | type=raw,enable=true,priority=200,prefix=,suffix=,value=${{ inputs.sha }} flavor: | - latest=${{ steps.meta-latest.outputs.latest }} + # latest=${{ steps.meta-latest.outputs.latest }} + latest=false + + - name: Use SSH key + uses: toptal/ssh-agent@v0.4.1 + with: + ssh-private-key: ${{ env.TOPTAL_BUILD_BOT_SSH_KEY }} - name: Login to Google Artifact Registry - GAR uses: docker/login-action@v3 @@ -75,12 +66,19 @@ runs: username: _json_key password: ${{ env.GCR_ACCOUNT_KEY }} - - name: Set up Docker Buildx - id: buildx + - name: Set up Dcoker Buildx - CI custom runners + if: contains(runner.name, 'inf-gha-runners-runners') + uses: docker/setup-buildx-action@v3 + with: + driver: remote + endpoint: 'tcp://10.154.0.46:1234' + + - name: Set up Docker Buildx - GH runners + if: "!contains(runner.name, 'inf-gha-runners-runners')" uses: docker/setup-buildx-action@v3 - name: Build and push release image - uses: docker/build-push-action@v5.1.0 + uses: docker/build-push-action@v5 with: provenance: false tags: ${{ steps.meta.outputs.tags }} @@ -88,3 +86,4 @@ runs: context: . file: ${{ inputs.docker-file }} build-args: ${{ inputs.build-args }} + ssh: default