GitHub Actions
How to use Nx Container Plugin in your GitHub Actions workflows
To build your container images with Github Actions, you have two different options, you can use the preinstalled software provided by the hosted runners or you can go with a container based job using one of the provided custom builder images:
- gperdomor/nx-docker with Node, Docker and Buildx integrated. Required to use
docker
engine. - gperdomor/nx-podman with Node and Podman integrated. Required to use
podman
engine.
Examples:
You may want your build result to be available in the Docker client through docker images
to be able to use it in another step of your workflow:
jobs:
build-with-docker-engine:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Login to DockerHub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- uses: actions/setup-node@v3
with:
cache: 'npm'
node-version-file: '.nvmrc'
- name: 'Install Dependencies'
run: npm install
- name: Derive appropriate SHAs for base and head for `nx affected` commands
uses: nrwl/nx-set-shas@v4
- name: 'Build images'
run: INPUT_GITHUB_TOKEN=${{ secrets.GITHUB_TOKEN }} npx nx affected --base=$NX_BASE --head=$NX_HEAD --target=container --parallel=2
You may want your build result to be available in the Docker client through docker images
to be able to use it in another step of your workflow:
jobs:
build-with-podman-engine:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Login to DockerHub
run: echo "$DOCKERHUB_TOKEN" | podman login -u $DOCKERHUB_USERNAME --password-stdin
env:
DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }}
DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_TOKEN }}
- uses: actions/setup-node@v3
with:
cache: 'npm'
node-version-file: '.nvmrc'
- name: 'Install Dependencies'
run: npm install
- name: Derive appropriate SHAs for base and head for `nx affected` commands
uses: nrwl/nx-set-shas@v4
- name: 'Build images'
run: npx nx affected --base=$NX_BASE --head=$NX_HEAD --target=container --parallel=2
Last updated on