We are going to edit the current workflow file in our repository by adding a job that turns our Dockerfile
into a Docker Image
.
- [Edit the current workflow file in our repository]({{ repoUrl }}/blob/docker-workflow/.github/workflows/ci-workflow.yml)
- Rename
ci-workflow.yml
tocd-workflow.yml
: - On line 1, change the name from
Node CI
toDocker CD
yaml name: Docker CD
- Add the following job to your workflow file:
Build-and-Push-Docker-Image:
runs-on: ubuntu-latest
needs: test
name: Docker Build, Tag, Push
steps:
- name: Checkout
uses: actions/checkout@v1
- name: Download built artifact
uses: actions/download-artifact@main
with:
name: webpack artifacts
path: public
- name: Build container image
uses: docker/build-push-action@v1
with:
username: {% raw %}${{github.actor}}{% endraw %}
password: {% raw %}${{secrets.GITHUB_TOKEN}}{% endraw %}
registry: docker.pkg.github.com
repository: {{ user.login }}/github-actions-for-packages/tic-tac-toe
tag_with_sha: true
- Commit the newly edited workflow file to your repository
Complete cd-workflow.yml file...
name: Docker CD
on:
push:
paths:
- "**Dockerfile**"
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- name: npm install and build webpack
run: |
npm install
npm run build
- uses: actions/upload-artifact@main
with:
name: webpack artifacts
path: public/
test:
runs-on: ubuntu-latest
needs: build
strategy:
matrix:
os: [ubuntu-lastest, windows-2016]
node-version: [12.x, 14.x]
steps:
- uses: actions/checkout@v1
- name: Use Node.js {% raw %}${{ matrix.node-version }}{% endraw %}
uses: actions/setup-node@v1
with:
node-version: {% raw %}${{ matrix.node-version }}{% endraw %}
- uses: actions/download-artifact@main
with:
name: webpack artifacts
path: public
- name: npm install, and test
run: |
npm install
npm test
env:
CI: true
Build-and-Push-Docker-Image:
runs-on: ubuntu-latest
needs: test
name: Docker Build, Tag, Push
steps:
- name: Checkout
uses: actions/checkout@v1
- name: Download built artifact
uses: actions/download-artifact@main
with:
name: webpack artifacts
path: public
- name: Build container image
uses: docker/build-push-action@v1
with:
username: {% raw %}${{github.actor}}{% endraw %}
password: {% raw %}${{secrets.GITHUB_TOKEN}}{% endraw %}
registry: docker.pkg.github.com
repository: {{ user.login }}/github-actions-for-packages/tic-tac-toe
tag_with_sha: true