Skip to content

Commit b7aeb4d

Browse files
committed
Continuous Delivery - Build Docker image and publish to Docker Hub and GitHub Container Registry
- created Dockerfile and docker-compose.yml with build configuration, - added GitHub Action setup for publishing docker images to Docker Hub and GitHub Container Registry. - added instructions in README file
1 parent 3b2632a commit b7aeb4d

File tree

6 files changed

+382
-15
lines changed

6 files changed

+382
-15
lines changed

.github/workflows/samples_simple.yml

Lines changed: 46 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
name: Node.js CI
1+
name: Node.js Continuous Integration and Continuous Delivery
22

33
on:
44
# run it on push to the default repository branch
55
push:
6-
branches: [$default-branch]
6+
branches: [main]
77
# run it during pull request
88
pull_request:
99

@@ -13,7 +13,8 @@ defaults:
1313
working-directory: samples/simple
1414

1515
jobs:
16-
build:
16+
build-and-test-code:
17+
name: Build and test application code
1718
# use system defined below in the tests matrix
1819
runs-on: ${{ matrix.os }}
1920

@@ -40,3 +41,45 @@ jobs:
4041
- run: npm run build:ts
4142
# run tests
4243
- run: npm test
44+
45+
build-and-push-docker-image:
46+
name: Build Docker image and push to repositories
47+
# run only when code is compiling and tests are passing
48+
needs: build-and-test-code
49+
runs-on: ubuntu-latest
50+
51+
steps:
52+
- uses: actions/checkout@v2
53+
54+
# setup Docker buld action
55+
- name: Set up Docker Buildx
56+
id: buildx
57+
uses: docker/setup-buildx-action@v1
58+
59+
- name: Login to DockerHub
60+
uses: docker/login-action@v1
61+
with:
62+
username: ${{ secrets.DOCKERHUB_USERNAME }}
63+
password: ${{ secrets.DOCKERHUB_TOKEN }}
64+
65+
- name: Login to Github Packages
66+
uses: docker/login-action@v1
67+
with:
68+
registry: ghcr.io
69+
username: ${{ github.actor }}
70+
password: ${{ secrets.GHCR_PAT }}
71+
72+
- name: Build image and push to Docker Hub and GitHub Container Registry
73+
uses: docker/build-push-action@v2
74+
with:
75+
# relative path to the place where source code (with package.json) is located
76+
context: ./samples/simple
77+
# Note: tags has to be all lower-case
78+
tags: |
79+
oskardudycz/eventsourcing.nodejs.simple:latest
80+
ghcr.io/oskardudycz/eventsourcing.nodejs/simple:latest
81+
# build on feature branches, push only on main branc
82+
push: ${{ github.ref == 'refs/heads/main' }}
83+
84+
- name: Image digest
85+
run: echo ${{ steps.docker_build.outputs.digest }}

0 commit comments

Comments
 (0)