-
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.
Merge pull request #1 from aviemet/docker
feat(docker): sets up docker as a release method
- Loading branch information
Showing
10 changed files
with
248 additions
and
64 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,28 @@ | ||
.git* | ||
.dockerignore | ||
.env.* | ||
*.env | ||
.rubocop* | ||
.solargraph* | ||
.eslintrc.js | ||
.rspec | ||
.vscode | ||
.circleci | ||
.storybook | ||
commitlint.config.js | ||
Procfile.dev | ||
stylelint.config.js | ||
**/node_modules | ||
coverage | ||
app/frontend/stories | ||
app/frontend/tests | ||
config/master.key | ||
config/credentials.yml.enc | ||
public/vite-dev | ||
public/vite-test | ||
log | ||
spec | ||
Procfile.dev | ||
vitest.config.ts | ||
rubocop-* | ||
**/.keep |
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 @@ | ||
source .env |
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,43 @@ | ||
name: Release | ||
|
||
on: | ||
workflow_dispatch: | ||
|
||
jobs: | ||
release: | ||
runs-on: ubuntu-latest | ||
|
||
name: "Bump version and publish docker image" | ||
|
||
permissions: write-all | ||
|
||
steps: | ||
- name: Check out | ||
uses: actions/checkout@v3 | ||
with: | ||
persist-credentials: false | ||
|
||
- name: Version Bump | ||
run: | | ||
npm install -g commitlint semantic-release semantic-release-github-actions-tags @semantic-release/changelog @semantic-release/git | ||
npx semantic-release --ci | ||
env: | ||
GH_TOKEN: ${{ secrets.GH_AUTH_TOKEN }} | ||
|
||
- name: Build Docker Image | ||
env: | ||
POSTGRES_USER: ${{ env.POSTGRES_USER }} | ||
POSTGRES_PASSWORD: ${{ env.POSTGRES_PASSWORD }} | ||
run: | | ||
docker-compose -f docker-compose.yml build | ||
- name: Authenticate to GitHub Container Registry | ||
run: echo ${{ secrets.GH_AUTH_TOKEN }} | docker login ghcr.io -u ${{ github.repository_owner }} --password-stdin | ||
|
||
- name: Push Docker Image to GitHub Packages | ||
run: | | ||
NEW_VERSION=$(node -p "require('./package.json').version") | ||
docker tag osc ghcr.io/${{ github.repository_owner }}/osc:${NEW_VERSION} | ||
docker push ghcr.io/${{ github.repository_owner }}/osc:${NEW_VERSION} | ||
env: | ||
GHCR_PAT: ${{ secrets.GH_AUTH_TOKEN }} |
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,71 @@ | ||
name: Ruby | ||
|
||
on: | ||
pull_request: | ||
branches: | ||
- main | ||
- dev | ||
|
||
jobs: | ||
test: | ||
|
||
runs-on: ubuntu-latest | ||
|
||
env: | ||
POSTGRES_USER: osc | ||
POSTGRES_PASSWORD: osc | ||
POSTGRES_HOST: localhost | ||
POSTGRES_DB: osc_test | ||
|
||
services: | ||
postgres: | ||
image: postgres:15-alpine | ||
env: | ||
POSTGRES_USER: ${{ env.POSTGRES_USER }} | ||
POSTGRES_PASSWORD: ${{ env.POSTGRES_PASSWORD }} | ||
POSTGRES_DB: ${{ env.POSTGRES_DB }} | ||
POSTGRES_HOST_AUTH_METHOD: trust | ||
ports: ['5432:5432'] | ||
options: | ||
--health-cmd pg_isready | ||
--health-interval 10s | ||
--health-timeout 5s | ||
--health-retries 5 | ||
|
||
steps: | ||
- uses: actions/checkout@v4 | ||
|
||
- name: Set up Ruby | ||
uses: ruby/setup-ruby@v1 | ||
with: | ||
bundler-cache: true | ||
|
||
- name: Set up Node | ||
uses: actions/setup-node@v3 | ||
with: | ||
node-version: 19.x | ||
cache: 'yarn' | ||
|
||
- name: Set up Yarn | ||
run: npm install -g yarn | ||
|
||
- name: Install Ruby dependencies | ||
run: bundle install --jobs 4 --retry 3 | ||
|
||
- name: Install Node.js dependencies | ||
run: yarn install | ||
|
||
- name: Prepare database | ||
env: | ||
DATABASE_URL: postgres://${{ env.POSTGRES_USER }}:${{ env.POSTGRES_PASSWORD }}@${{ env.POSTGRES_HOST }}:5432/${{ env.POSTGRES_DB }} | ||
RAILS_ENV: test | ||
run: | | ||
bundle exec rails db:prepare | ||
- name: Run tests | ||
env: | ||
DATABASE_URL: postgres://${{ env.POSTGRES_USER }}:${{ env.POSTGRES_PASSWORD }}@${{ env.POSTGRES_HOST }}:5432/${{ env.POSTGRES_DB }} | ||
run: bundle exec rspec | ||
|
||
- name: Run Vite tests | ||
run: yarn test |
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,57 @@ | ||
ARG RUBY_VERSION=3.2.2 | ||
|
||
FROM ruby:$RUBY_VERSION AS BUILD_IMAGE | ||
|
||
ARG BUNDLER_VERSION=2.4.17 | ||
ARG NODE_MAJOR_VERSION=20 | ||
|
||
ADD . /osc | ||
WORKDIR /osc | ||
|
||
# Install basic packages | ||
RUN apt-get update && apt-get install -y build-essential libvips postgresql-client ca-certificates curl gnupg | ||
|
||
# Install Node | ||
RUN mkdir -p /etc/apt/keyrings | ||
RUN curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg | ||
RUN echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_$NODE_MAJOR_VERSION.x nodistro main" | tee /etc/apt/sources.list.d/nodesource.list | ||
RUN apt-get update && apt-get install -y nodejs | ||
RUN npm i -g yarn && yarn set version stable | ||
|
||
# Clean up apt | ||
RUN apt-get clean && rm -rf /var/lib/apt/lists/* /usr/share/doc /usr/share/man | ||
|
||
# Rails app lives here | ||
WORKDIR /osc | ||
|
||
# Set production environment | ||
ENV RAILS_LOG_TO_STDOUT="1" | ||
ENV RAILS_SERVE_STATIC_FILES true | ||
ENV RAILS_ENV production | ||
# ENV BUNDLE_WITHOUT development | ||
ENV NODE_ENV production | ||
|
||
# Install application gems | ||
COPY Gemfile Gemfile.lock ./ | ||
RUN gem uninstall bundler && gem install bundler -v $BUNDLER_VERSION | ||
RUN bundle install | ||
|
||
# Install npm packages | ||
COPY package.json yarn.lock ./ | ||
RUN yarn install | ||
|
||
# Copy application code | ||
COPY ./docker_copy_files.sh . | ||
RUN chmod +x ./docker_copy_files.sh | ||
RUN ./docker_copy_files.sh | ||
|
||
# Precompile bootsnap code for faster boot times | ||
RUN bundle exec bootsnap precompile --gemfile app/ lib/ | ||
|
||
# Precompiling assets for production without requiring secret RAILS_MASTER_KEY | ||
RUN SECRET_KEY_BASE=DUMMY bundle exec rails assets:precompile | ||
|
||
# Entrypoint prepares the database | ||
ENTRYPOINT ["/osc/bin/docker-entrypoint"] | ||
|
||
EXPOSE 3000 |
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 |
---|---|---|
|
@@ -5,4 +5,8 @@ class Scope < Scope | |
def options? | ||
standard_auth(:options) | ||
end | ||
|
||
def execute? | ||
standard_auth(:options) | ||
end | ||
end |
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
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 @@ | ||
xHhAOBZLKEaTJ/9qV9XhMqoBGlI7ImpGAEQhUTc1VJ9kgcp8K3H50oFMew3XPO4WNp30MMAy3xRQ4d2/xLG8PDUZ9dINxOae+lCro/vbJPNe3eYkVHAB/2O0iSeFSrr+Cg2D/NsM0cWy4X0H/E7+b0xNah/NvBokM51/OUOGa2q6c7621WzOHz7ODElpVeNkF3UrUHnbFfKCstATj4sjkV9HYx3iDoMmANITpvG/Z+To75zBacVqGJ59+G3bsdsnW61FuTdIsLMElgzgZY1FKzJMnDG8VA6QeBG2YzPnzgV+07RzwTFZ3PbsFi7m134SOZzoX6DlQX+zVtUM8d6qO465uLM3VPllTLgb8sy4/vdElolna2rgMsiXsd/P47UJMAwbdfPgVG9sWJ+uiUhHEXdswPd3LchffncH--7YUaJqXSCfgaa9GR--iy2s+hie4ej5vbzXddVObw== |
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,38 @@ | ||
version: '3.9' | ||
|
||
services: | ||
postgres: | ||
image: postgres:15.4-alpine | ||
environment: | ||
POSTGRES_USER: "${POSTGRES_USER}" | ||
POSTGRES_PASSWORD: "${POSTGRES_PASSWORD}" | ||
volumes: | ||
- postgres:/var/lib/postgresql/data | ||
restart: always | ||
|
||
web: | ||
image: osc_controller | ||
build: . | ||
command: > | ||
bash -c "bin/docker-entrypoint" | ||
volumes: | ||
- .:/osc | ||
- files:/osc/storage | ||
- secrets:/osc/config/secrets | ||
ports: | ||
- "80:3000" | ||
depends_on: | ||
- postgres | ||
environment: | ||
RACK_ENV: "production" | ||
RAILS_ENV: "production" | ||
NODE_ENV: "production" | ||
POSTGRES_USER: "${POSTGRES_USER}" | ||
POSTGRES_PASSWORD: "${POSTGRES_PASSWORD}" | ||
POSTGRES_HOST: postgres | ||
restart: always | ||
|
||
volumes: | ||
postgres: | ||
files: | ||
secrets: |