Skip to content

Commit

Permalink
#2 Replace circleci test with gitlab actions build (#5)
Browse files Browse the repository at this point in the history
* #2 Replace circleci test with gitlab actions build
* #2 Migrate npm publish to github actions
* #2 Remove version from package.json and instead inject in ci based on tag
* #2 Add missing quotes when setting package version
* #2 Migrate dockerhub push job from circleci to github actions
* #2 Replace deprecated --production with --omit=dev for npm installs
* #2 Remove docker buildx actions
* #2 Add debug step printing directory contents
* #2 Use local context for build
* #2 Add missing script to build artifacts
* #2 Add missng nginx.conf to artifacts
* #2 Fix image name and job dependencies
  • Loading branch information
danielemery authored Oct 7, 2023
1 parent 62afb9b commit 3bbb792
Show file tree
Hide file tree
Showing 6 changed files with 157 additions and 168 deletions.
164 changes: 0 additions & 164 deletions .circleci/config.yml

This file was deleted.

2 changes: 1 addition & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.circleci
.github
bin
cli
dist
Expand Down
143 changes: 143 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
name: CI

on:
push:
tags:
- 'v[0-9]+.[0-9]+.[0-9]+*'
pull_request:
branches: ['main']

env:
REGISTRY: demery
IMAGE_NAME: docker-react
NODE_VERSION: 18.18.0

jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Configure node
uses: actions/setup-node@v3
with:
node-version: ${{ env.NODE_VERSION }}

- name: Install packages
run: npm ci

- name: Build
run: npm run build

- name: Test
run: npm t

- name: Upload build artifacts
uses: actions/upload-artifact@v3
with:
name: artifacts
path: |
dist
bin
Dockerfile
.dockerignore
nginx.conf
docker-react-entrypoint.sh
.npmignore
package*.json
README.md
publish-npm:
needs: build
runs-on: ubuntu-latest
if: startsWith(github.ref, 'refs/tags/v')
steps:
- uses: nowsprinting/check-version-format-action@v3
id: version
with:
prefix: 'v'

- name: Download artifacts
uses: actions/download-artifact@v3
with:
name: artifacts
if: steps.version.outputs.is_valid == 'true'

- name: set package json version
uses: jaywcjlove/github-action-package@main
with:
data: |
{
"version": "${{steps.version.outputs.full_without_prefix}}"
}
if: steps.version.outputs.is_valid == 'true'

- name: Configure node
uses: actions/setup-node@v3
with:
node-version: ${{ env.NODE_VERSION }}
if: steps.version.outputs.is_valid == 'true'

- name: Authenticate with npm
run: echo "//registry.npmjs.org/:_authToken=${{secrets.NPM_TOKEN}}" > ~/.npmrc
if: steps.version.outputs.is_valid == 'true'

- name: Install packages
run: npm ci --omit=dev
if: steps.version.outputs.is_valid == 'true'

- name: Publish to npm (stable channel)
run: npm publish --access public
if: steps.version.outputs.is_valid == 'true' && steps.version.outputs.is_stable == 'true'

- name: Publish to npm (beta channel)
run: npm publish --access public --tag beta
if: steps.version.outputs.is_valid == 'true' && steps.version.outputs.is_stable == 'false'

publish-docker:
needs: publish-npm
runs-on: ubuntu-latest
if: startsWith(github.ref, 'refs/tags/v')
steps:
- uses: nowsprinting/check-version-format-action@v3
id: version
with:
prefix: 'v'

- name: Download artifacts
uses: actions/download-artifact@v3
with:
name: artifacts
if: steps.version.outputs.is_valid == 'true'

- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ vars.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
if: steps.version.outputs.is_valid == 'true'

- name: Install packages
run: npm ci --omit=dev
if: steps.version.outputs.is_valid == 'true'

- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
flavor: |
latest=${{ steps.version.outputs.is_stable == 'true' && 'true' || 'false' }}
if: steps.version.outputs.is_valid == 'true'

- name: Build and push
uses: docker/build-push-action@v5
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
build-args: |
DOCKER_REACT_VERSION=${{ steps.version.outputs.full }}
if: steps.version.outputs.is_valid == 'true'
13 changes: 13 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,15 @@
# Ignore source & configuration code
src
tsconfig.json
prettier.config.cjs
sample.joi.schema.js
.github

# Ignore docker-related files
Dockerfile
.dockerignore
docker-react-entrypoint.sh
nginx.conf

# Ignore nix development flakes
flake.*
2 changes: 0 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{
"name": "docker-react",
"version": "0.0.3",
"description": "Tooling to deploy React applications with docker containers.",
"main": "dist/index.js",
"type": "module",
Expand Down

0 comments on commit 3bbb792

Please sign in to comment.