-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: services CD and Docker steps in CI (#10)
Several changes to enable Docker builds for all services: - Added a web-client build stage to the Dockerfile - Added dummy `package.json` files to services without web-clients (I don't like this workaround but it's fine for now) - Updated ignore files - Added Docker steps to the services CI workflow - Added a CD workflow for services
- Loading branch information
Showing
7 changed files
with
225 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
**/node_modules | ||
**/dist | ||
.vscode | ||
**/.vscode | ||
.git | ||
.gitignore | ||
Dockerfile | ||
.dockerignore |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
name: services - CD | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
paths: | ||
- services/** | ||
|
||
env: | ||
REGISTRY: ${{ vars.REGISTRY || 'ghcr.io' }} | ||
TARGET_PLATFORMS: linux/amd64,linux/arm64 | ||
|
||
concurrency: | ||
group: ${{ github.workflow }}-${{ github.ref }} | ||
cancel-in-progress: ${{ github.ref != 'refs/heads/main' }} | ||
|
||
jobs: | ||
changed: | ||
name: Prepare | ||
uses: ./.github/workflows/changes.yml | ||
with: | ||
path: services | ||
dir_names_max_depth: 2 | ||
|
||
build-and-test: | ||
name: Build-Test (${{ matrix.service-path }}) | ||
# needs: [changed] | ||
runs-on: ubuntu-latest | ||
# if: needs.changed.outputs.any_changed == 'true' | ||
strategy: | ||
matrix: | ||
go-version: ['1.21.x'] | ||
# service-path: ${{ fromJSON(needs.changed.outputs.matrix) }} | ||
service-path: [ 'examples/crud', 'examples/echo'] | ||
steps: | ||
- uses: actions/checkout@v4 | ||
|
||
- uses: actions/setup-node@v4 | ||
with: | ||
node-version: 18 | ||
cache-dependency-path: services/${{ matrix.service-path }}/web-client/package-lock.json | ||
|
||
- name: Install Node dependencies | ||
run: | | ||
cd services/${{ matrix.service-path }}/web-client && | ||
npm i -D @swc/cli @swc/core && | ||
npm install | ||
- name: Build web-client | ||
run: | | ||
cd services/${{ matrix.service-path }}/web-client && | ||
npm run build | ||
- uses: actions/setup-go@v5 | ||
with: | ||
go-version: ${{ matrix.go-version }} | ||
cache-dependency-path: services/${{ matrix.service-path }}/go.sum | ||
|
||
- name: Test | ||
working-directory: services/${{ matrix.service-path }} | ||
run: go test ./... | ||
|
||
- name: Build | ||
working-directory: services/${{ matrix.service-path }} | ||
run: go build main.go | ||
|
||
docker-image: | ||
name: Docker Image (${{ matrix.service-path }}) | ||
needs: [changed] | ||
runs-on: ubuntu-latest | ||
if: needs.changed.outputs.any_changed == 'true' | ||
strategy: | ||
matrix: | ||
service-path: ${{ fromJSON(needs.changed.outputs.matrix) }} | ||
steps: | ||
- uses: actions/checkout@v4 | ||
|
||
- name: Extract service info | ||
id: info | ||
run: | | ||
echo "domain=$(dirname ${{ matrix.service-path }})" >> $GITHUB_OUTPUT | ||
echo "service=$(basename ${{ matrix.service-path }})" >> $GITHUB_OUTPUT | ||
- name: Log in to the Container registry | ||
uses: docker/login-action@v3 | ||
with: | ||
registry: ${{ env.REGISTRY }} | ||
username: ${{ secrets.DOCKER_USERNAME || (env.REGISTRY == 'ghcr.io' && github.actor) }} | ||
password: ${{ secrets.DOCKER_PASSWORD || (env.REGISTRY == 'ghcr.io' && secrets.GITHUB_TOKEN) }} | ||
|
||
- name: Extract metadata (tags, labels) for Docker | ||
id: meta | ||
uses: docker/metadata-action@v5 | ||
with: | ||
images: ${{ env.REGISTRY }}/${{ github.repository }}-${{ steps.info.outputs.domain}}-${{ steps.info.outputs.service }} | ||
tags: | | ||
type=sha | ||
type=edge,branch=main | ||
type=schedule,pattern={{date 'YYYYMMDD-hhmmss' tz='America/Chicago'}} | ||
- name: Set up QEMU | ||
uses: docker/setup-qemu-action@v3 | ||
|
||
- name: Set up Docker Buildx | ||
uses: docker/setup-buildx-action@v3 | ||
|
||
- name: Build and push Docker image | ||
uses: docker/build-push-action@v5 | ||
with: | ||
context: . | ||
file: Dockerfile | ||
push: true | ||
tags: ${{ steps.meta.outputs.tags }} | ||
labels: ${{ steps.meta.outputs.labels }} | ||
platforms: ${{ env.TARGET_PLATFORMS }} | ||
build-args: | | ||
DOMAIN=${{ steps.info.outputs.domain}} | ||
SERVICE=${{ steps.info.outputs.service}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,14 @@ | ||
services/blueprint/web-client/target | ||
pipelines/secrets | ||
|
||
node_1 | ||
node_2 | ||
node_3 | ||
|
||
.DS_Store | ||
node_modules/ | ||
|
||
__debug_* | ||
|
||
target/ | ||
node_modules | ||
dist | ||
target | ||
main |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"name": "placeholder", | ||
"scripts": { | ||
"build": "" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"name": "placeholder", | ||
"scripts": { | ||
"build": "" | ||
} | ||
} |