Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: publishing images per environment #198

Merged
merged 8 commits into from
Jan 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
File renamed without changes.
5 changes: 5 additions & 0 deletions .env.production
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
REACT_APP_AAD_CLIENT_ID=e8a0f8e6-059b-426f-9011-40f463640285
REACT_APP_AAD_TENANT_ID=3aa4a235-b6e2-48d5-9195-7fcf05b459b0
REACT_APP_AAD_REDIRECT_URI=/
REACT_APP_BACKEND_URL=https://api-pepm-dev.radix.equinor.com
REACT_APP_BACKEND_API_SCOPE=api://e8a0f8e6-059b-426f-9011-40f463640285/read
5 changes: 5 additions & 0 deletions .env.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
REACT_APP_AAD_CLIENT_ID=968bcf2a-6292-441d-bbd9-755a3a8f3ec1
REACT_APP_AAD_TENANT_ID=3aa4a235-b6e2-48d5-9195-7fcf05b459b0
REACT_APP_AAD_REDIRECT_URI=/
REACT_APP_BACKEND_URL=https://api-pepm-test.radix.equinor.com/
REACT_APP_BACKEND_API_SCOPE=api://968bcf2a-6292-441d-bbd9-755a3a8f3ec1/read
15 changes: 13 additions & 2 deletions .github/workflows/on-push-main.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
on:
workflow_call
push:
branches:
main


jobs:
publish-latest:
publish-image:
strategy:
matrix:
environment: [dev, test, production]

uses: ./.github/workflows/publish.yaml
with:
ENVIRONMENT: ${{ matrix.environment }}


4 changes: 2 additions & 2 deletions .github/workflows/on-tag.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ jobs:
publish-prod:
uses: ./.github/workflows/publish.yaml
with:
IMAGE_TAG: production
ENVIRONMENT: production

publish-tag:
needs: [set-tag-ref]
uses: ./.github/workflows/publish.yaml
with:
IMAGE_TAG: ${{ needs.set-tag-ref.outputs.tag-ref }}
ENVIRONMENT: ${{ needs.set-tag-ref.outputs.tag-ref }}
10 changes: 5 additions & 5 deletions .github/workflows/publish.yaml
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
on:
workflow_call:
inputs:
IMAGE_TAG:
default: latest
ENVIRONMENT:
type: string

jobs:
build-and-publish:
name: Build and Publish
runs-on: ubuntu-latest
environment: ${{inputs.ENVIRONMENT}}

steps:
- uses: actions/checkout@master
- run: echo "Tagging with ${{inputs.IMAGE_TAG}}"
- run: echo "Tagging with ${{inputs.ENVIRONMENT}}"

- name: Build Container Image
run: IMAGE_TAG=${{inputs.IMAGE_TAG}} docker compose build
run: ENVIRONMENT=${{inputs.ENVIRONMENT}} docker compose build

- name: Authenticate Against Container Registry
run: echo ${{ secrets.GITHUB_TOKEN }} | docker login ghcr.io -u $GITHUB_ACTOR --password-stdin

- name: Publish Container Image
run: IMAGE_TAG=${{inputs.IMAGE_TAG}} docker compose push
run: ENVIRONMENT=${{inputs.ENVIRONMENT}} docker compose push
32 changes: 29 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,40 @@ COPY package.json yarn.lock ./
RUN yarn install --ignore-scripts --frozen-lockfile --link-duplicates
COPY . .

FROM base AS development
FROM base AS local
CMD ["yarn", "start"]

FROM base AS production
FROM base AS dev

RUN yarn global add serve
RUN yarn run build:dev
# Add non-root user
RUN deluser --remove-home node \
&& addgroup -S node -g 1001 \
&& adduser -S -G node -u 1001 node

USER 1001
EXPOSE 3000
CMD ["serve", "build", "--listen", "3000"]


FROM base AS test

RUN yarn global add serve
RUN yarn build
RUN yarn run build:test
# Add non-root user
RUN deluser --remove-home node \
&& addgroup -S node -g 1001 \
&& adduser -S -G node -u 1001 node

USER 1001
EXPOSE 3000
CMD ["serve", "build", "--listen", "3000"]

FROM base AS production

RUN yarn global add serve
RUN yarn run build:production
# Add non-root user
RUN deluser --remove-home node \
&& addgroup -S node -g 1001 \
Expand Down
5 changes: 3 additions & 2 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
version: '3.9'
services:

pepm-ui:
image: ghcr.io/equinor/pepm-ui/pepm-ui:${IMAGE_TAG:-latest}
image: ghcr.io/equinor/pepm-ui/pepm-ui:${ENVIRONMENT}.latest
build:
target: production
target: ${ENVIRONMENT}
context: .
ports:
- 3000:3000
6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"@types/react": "^18.0.0",
"@types/react-dom": "^18.0.0",
"axios": "^1.6.0",
"env-cmd": "^10.1.0",
"openapi-fetch": "^0.7.2",
"openapi-typescript-codegen": "^0.25.0",
"react": "^18.2.0",
Expand All @@ -34,7 +35,10 @@
"zod": "^3.22.4"
},
"scripts": {
"start": "react-scripts start",
"start": "env-cmd -f .env.local react-scripts start",
"build:dev": "env-cmd -f .env.dev react-scripts build",
"build:test": "env-cmd -f .env.test react-scripts build",
"build:production": "env-cmd -f .env.production react-scripts build",
"build": "react-scripts build",
"test": "react-scripts test --transformIgnorePatterns \"node_modules/(?!axios)/\"",
"test:ts": "tsc --noEmit",
Expand Down
11 changes: 4 additions & 7 deletions radixconfig.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,18 @@ spec:
- name: prod
components:
- name: web
src: .
image: ghcr.io/equinor/pepm-core-api/pepm-api:{imageTagName}
publicPort: http
ports:
- name: http
port: 3000
variables:
REACT_APP_AAD_TENANT_ID: ""
REACT_APP_AAD_CLIENT_ID: ""
REACT_APP_AAD_REDIRECT_URI: ""
REACT_APP_BACKEND_URL: ""
REACT_APP_BACKEND_API_SCOPE: ""
environmentConfig:
- environment: dev
imageTagName: dev.latest
- environment: test
imageTagName: test.latest
- environment: prod
imageTagName: production.latest
- name: api
image: ghcr.io/equinor/pepm-core-api/pepm-api:{imageTagName}
publicPort: http
Expand Down
10 changes: 9 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3851,7 +3851,7 @@ cosmiconfig@^7.0.0:
path-type "^4.0.0"
yaml "^1.10.0"

cross-spawn@^7.0.2, cross-spawn@^7.0.3:
cross-spawn@^7.0.0, cross-spawn@^7.0.2, cross-spawn@^7.0.3:
version "7.0.3"
resolved "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.3.tgz"
integrity sha512-iRDPJKUPVEND7dHPO8rkbOnPpyDygcDFtWjpeWNCgy8WP2rXcxXL8TskReQl6OrB2G7+UJrags1q15Fudc7G6w==
Expand Down Expand Up @@ -4459,6 +4459,14 @@ entities@^2.0.0:
resolved "https://registry.npmjs.org/entities/-/entities-2.2.0.tgz"
integrity sha512-p92if5Nz619I0w+akJrLZH0MX0Pb5DX39XOwQTtXSdQQOaYH03S1uIQp4mhOZtAXrxq4ViO67YTiLBo2638o9A==

env-cmd@^10.1.0:
version "10.1.0"
resolved "https://registry.yarnpkg.com/env-cmd/-/env-cmd-10.1.0.tgz#c7f5d3b550c9519f137fdac4dd8fb6866a8c8c4b"
integrity sha512-mMdWTT9XKN7yNth/6N6g2GuKuJTsKMDHlQFUDacb/heQRRWOTIZ42t1rMHnQu4jYxU1ajdTeJM+9eEETlqToMA==
dependencies:
commander "^4.0.0"
cross-spawn "^7.0.0"

error-ex@^1.3.1:
version "1.3.2"
resolved "https://registry.npmjs.org/error-ex/-/error-ex-1.3.2.tgz"
Expand Down